public class EqualTest {
public static void main(String[] args) {
Integer i1 = 1000;
Integer i2 = 1000;
if(i1 == i2)
{System.out.println("Same objects");}
if(i1!=i2)
{System.out.println("Different Objects");}
if(i1.equals(i2))
{System.out.println("meaningfully equal");}
Integer i3 = 10;
Integer i4 = 10;
if(i3 == i4)
{System.out.println("same object");}
if(i3 != i4)
{System.out.println("Different object");}
if(i3.equals(i4))
{System.out.println("meaningfully equal");}
}
}
输出的结果是:
Different Objects
meaningfully equal
same object
meaningfully equal
结果让我感觉不是太理解,为什么上面
Integer i1 = 1000;
Integer i2 = 1000;
而下面
Integer i3 = 10;
Integer i4 = 10;
的结果会不一样呢?
请大家帮忙看看,谢谢!