1. Integer i1 = 40;
    2. Integer i2 = 40;
    3. Integer i3 = 0;
    4. Integer i4 = new Integer(40);
    5. Integer i5 = new Integer(40);
    6. Integer i6 = new Integer(0);
    7. System.out.println("i1=i2 " + (i1 == i2)); //true
    8. System.out.println("i1=i2+i3 " + (i1 == i2 + i3));// true
    9. System.out.println("i1=i4 " + (i1 == i4)); //false
    10. System.out.println("i4=i5 " + (i4 == i5));//false
    11. System.out.println("i4=i5+i6 " + (i4 == i5 + i6));//true
    12. System.out.println("40=i5+i6 " + (40 == i5 + i6)); //true


    1 System.out.println(“i1=i2 “ + (i1 == i2)); //true

    原因i1和i2 在 -128 到127 之间,同一个cahe

    2 System.out.println(“i1=i2+i3 “ + (i1 == i2 + i3));// true

    因为i2+i3计算之后直接退化为int

    3 System.out.println(“i1=i4 “ + (i1 == i4)); //false

    i1 是cahe中的 i4是新new出来的

    4 System.out.println(“i4=i5 “ + (i4 == i5));//false

    i4 i5 都是new出来的不一样

    5 System.out.println(“i4=i5+i6 “ + (i4 == i5 + i6));//true

    遇到运算直接拆包,i4==40 当然是true

    6 System.out.println(“40=i5+i6 “ + (40 == i5 + i6)); //true

    遇到运算直接拆包,40==40 当然是true