11_dark horse programmer _ Zhang Xiaoxiang _ Java basic reinforcement _ Automatic Disassembly box for basic data and metadata-sharing design mode
Public static void main (string ARGs []) {
Integer i11 = 1;
System. Out. println (i11 + 2 );
Integer i12 = 1;
System. Out. println (i11 = i12 );
Integer i21 = 128;
Integer i22 = 128;
System. Out. println (i21 = i22 );
}
I11 is created using boxing (from the basic data type int to integer), and the first output uses automatic unpacking (from integer to int, and then addition );
The second output is true, and the third output is false. Because integer uses the metadata design mode when only one byte exists, i11 and i12 are the same memory objects (how to express them ?), After i11 creates an object, i11 objects are directly used if the same object already exists before i12 is created.
Flyweight Design Model