public class TestWrapper1 { int num; Integer in ; public static void main(String[] args) { //1.某些方法参数是对象,为了让基本数据类型能作为参数 List list = new ArrayList(); list.add(new Integer(56)); //int 56 list.add(new Integer(100)); list.add(new Double(67.5)); list.add(99); System.out.println(list); //2.包装类还可以提供更多的功能 System.out.println(Integer.SIZE);
public class Integer extends Number { private final int value; public Integer(int value) { this.value = value; } @Override public int intValue() { return value; } }
public class Integer extends Number { private static class IntegerCache { static final int low = -128; static final int high; static final java.lang.Integer cache[]; static { int h = 127; high = h; cache = new java.lang.Integer[(high - low) + 1]; int j = low; for(int k = 0; k < cache.length; k++) cache[k] = new java.lang.Integer(j++); } private IntegerCache() {} } public static java.lang.Integer valueOf(int i) { if (i >= IntegerCache.low && i <= IntegerCache.high) return IntegerCache.cache[i + (-IntegerCache.low)]; return new java.lang.Integer(i); } }