Java == vs equals()
==比较的是:是否obj1和obj2在同一个内存.相比下,equals就是比较内容. 所以Object 要override equals() /*Integer vs Integer*/ Integer a = new Integer(256); Integer b = new Integer(256); System.out.println(a == b); //false System.out.println(a.equals(b)); // true /*Integer vs int*/ Integer a1 = new Integer(256); int b1 = 256; System.out.println(a1 == b1); //true (这里证明了, a1的内存地址和b1是一样的// ) System.out.println(a1.equals(b1)); //true /*Integer deep copy*/ Integer a2 = new Integer(256); Integer b2 […]