1. Java language foundation (2) _ types and operations - basic data type conversion

2018-04-11

 

Basic data type conversion

 

First, the data is too large and overflow

  overflow: data is outside the critical range of the data type

   If the overflow occurs, the program does not do the data check range processing, there will be data disorder (wen)

 

2. Automatic conversion of basic data types (implicit conversion)

  Among the eight basic types, boolean is not a numeric type and does not participate in conversion;

   Generally, byte, short, and char are not converted to each other, but directly convert byte, short, and char to int.

 

  Conversion rules:

    The space size of each type, (convert from small to large) see the picture:

    

 

   Think of different data types as containers of different capacities:

 

     

 

    

 

Second, the basic data type coercion (explicit conversion) 

  

 

1  // Assign a constant of type int directly to a variable of type byte 
2           byte a = 125 ;
 3  // Because the compiler finds that 125 is in the byte range, the bottom layer secretly converts it
View Code

 

Fourth, the automatic promotion of expression types

  

 

   

 

 

String type and any type of data are connected by "+", and the result is String (string) type

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324483674&siteId=291194637