1. The wrapper class object is immutable.
2.==, when the wrapper class and the basic type use = = comparison, the packaging class will be automatically disassembled for the basic type and then compare
3. Boolean,byte,char that is less than or equal to <=127, and short and int between -128~127 are wrapped in a fixed-address wrapper class object. But if the wrapper object is new, it will be assigned the address, is no longer fixed.
Such as:
Public Static voidMain (string[] args) {//TODO auto-generated Method StubInteger A =NewInteger (1); Integer b=NewInteger (1); intC=1; Integer D=1; Integer e=1; System. out. println ("a==b:"+ (a==b)); System. out. println ("d==e:"+ (d==e)); System. out. println ("a==c:"+ (a==c)); System. out. println ("a==e:"+ (a==e)); System. out. println ("c==e:"+ (c==e)); The result is: a==b:falseD==e:truea==c:truea==e:falseC==e:true
4. When declaring <=128 or -128~127, a fixed wrapper class is assigned, and the method of wrapping the class integer valueOf (String s) is also assigned a fixed wrapper class object. The source code is as follows:
Public Static Integer valueOf (int i) { int; if (I >=-127// must cache return Integercache.cache[i + offset]; } return New Integer (i); }
The Java design may be because the value of this range is the most used.
Java Basics Wrapper classes and basic types