Integer class of boxing and unboxing implemented

 Decompile: refers to a "reverse analysis, research," the work of others target software program (such as executable programs) to derive the idea of ​​other people's software products are used by, principles, structures, algorithms, processes, run method and other design elements, in certain cases the source may be deduced. Decompiled as reference for their own software, or directly for their own software products.

Test code:

 1 public class BoxAndUnbox {
 2 
 3     /**
 4      * @param args
 5      */
 6     public static void main(String[] args) {
 7         int value=100;
 8 
 9         Integer obj=value;  //装箱
10 
11         int result=obj*2;     //拆箱
12         System.out.println(obj);
13         System.out.println(result);
14 
15     }
16 
17 }

Results are as follows:

100

200

Decompile follows:

 

 (Non-operating their own computer Java file can not be run in cmd)

This shows that the packing is called automatically when the Integer valueOf (int) method. Automatically invoked When unpacking is intValue method of Integer.

Packing process is achieved by calling the method valueOf wrapper, the unpacking process is achieved by a method call intValue wrapper.

Guess you like

Origin www.cnblogs.com/cxy0210/p/11685027.html
Recommended