JavaSE---自动装箱、拆箱、foreach遍历
【notice】:
foreach遍历引用类型,会转为引用类型的iterator迭代,所以要求实现Iterator接口;
foreach遍历基本类型,与普通for循环一样
public static void main(String[] args) { /** * -> Integer.valueOf(1) * public static Integer valueOf(int i) { * if (i >= IntegerCache.low && i <= IntegerCache.high) * return IntegerCache.cache[i + (-IntegerCache.low)]; * return new Integer(i); * } */ Integer a =1; // Integer b =2; Integer c =3; Long d = 3L; System.out.println(a == b); /** * c.equals(a+b) * * public boolean equals(Object obj) { * if (obj instanceof Integer) { * return value == ((Integer)obj).intValue(); * } * return false; * } */ System.out.println(c.equals(a+b)); System.out.println(d.equals(c)); }