/* int is just a basic type. int has the corresponding class type, that is integer.
* For more operations on basic data types and more convenient operation, Java provides the corresponding class type-wrapper class type-for each basic data type. Each basic type assigns an operation that encapsulates the corresponding class type to make the basic type data more convenient.
* ByteByte
* Short Short
* INT Integer (this looks very special)
* Long Long
* Float Float
* Double Double
* Char Character (this looks very special)
* Boolean Boolean
*
* Used for conversions between basic data types and strings.
*/
New features of JDK5, automatic disassembly box.
/* * JDK5 new features * Auto Boxing: Converting a base type to a wrapper class type * Automatic unpacking: Converting wrapper class type to base type * */public class Integerdemo {public static void main (string[] args) {//defines a wrapper class type variable of type int i//integer i = new integer, Integer II = 100;//equivalent to the previous sentence, automatically converts 100 to the referenced Integer type II + = 200;//itself to different Type addition will error, and there is no error. This will not be an error, because the Automatic II into the int type is calculated. System.out.println ("II:" + II);//Through the anti-compilation code, the preceding three sentence is equivalent to the following three words//Integer II = integer.valueof (100); Auto-boxing//II = integer.valueof (Ii.intvalue () + 200); Automatic unpacking Ii.intvalue (), then automatically boxed integer.valueof (Ii.intvalue () + +);//System.out.println ((New StringBuilder ("II:")). Append (ii). toString ()); The result is a string type
Attention:
* When using the new JDK feature this way, Integer x = null; The code will appear nullpointerexception. Null pointer exception * It is recommended that you first determine whether it is null before you use it. if (iii! = NULL) {}
The code is as follows:
Integer III = null;//nullpointerexceptionif (iii! = NULL) {//Add judgment logic, this exception will not occur. III + = 1000; SYSTEM.OUT.PRINTLN (iii);}
Another attribute of the integer class: integer data is directly assigned, and if between 128 and 127, the data is fetched directly from the buffer pool.
By de-compiling, we know that for data between 128 and 127, a data buffer pool is made, and if the data is within that range, no new space is created each time (new addresses are not created)
An overview of the integer and auto-unboxing of the first season of JAV entry