包装类对象之间值的比较, 使用equals 方法

public class Demo01 {
    public static void main(String[] args) {
        //OOP 规约 7. 所有的相同类型的包装类对象之间值的比较,全部使用 equals 方法比较。
        Integer a = 12;
        Integer b = 12;
        System.out.println(a == b); // 在-128 至 127 之间的赋值,Integer 对象是在IntegerCache.cache 产生,会复用已有对象
        Integer c = 12334;
        Integer d = 12334;
        System.out.println(c == d); // 错误
        System.out.println(c.equals(d)); // 正确
    }

}
/*
result:
true
false
true
* */
原文地址:https://www.cnblogs.com/lixyuan/p/13338924.html