自动拆箱和自动装箱
- static Integer a = 30;
static Integer b = 30;
a==b
如果在不同的对象中;且超出缓存范围(-128~~127)即为false
普遍情况下equal都根据值判断,没有其他误差
package com.catches;
public class Demo06 {
static Integer a = 300;
static Integer b = 300;
public static void main(String[] args) {
Integer c = new Integer(30);
Integer d = new Integer(30);
/*System.out.println("equals"+(a.equals(b)));//true
System.out.println("=="+(a==b));//true
System.out.println("equals"+c.equals(d));//true*/
System.out.println("==***"+(a==b));//false
System.out.println(c);
System.out.println(d);
}
}