- inti = 25;
- Integer j = i;//自动装箱
- intm = j;//自动拆箱
- publicclassDemo {
- publicstaticvoid main(String[] args) {
- Integer a = 100;
- Integer b = 100;
- Integer c = 200;
- Integer d = 200;
- System.out.println(a==b);
- System.out.println(a==100);
- System.out.println(c==d);
- System.out.println(c==200);
- }
- }
- publicstaticInteger valueOf(inti) {
- finalintoffset = 128;
- if(i >= -128&& i <= 127) { // must cache
- returnIntegerCache.cache[i + offset];
- }
- returnnewInteger(i);
- }
- privatestaticclass IntegerCache {
- privateIntegerCache(){}
- staticfinalInteger cache[] = newInteger[-(-128) + 127+1];
- static{
- for(inti = 0; i < cache.length; i++)
- cache[i] = newInteger(i - 128);
- }
- }