public static void main(String[] args) {
// TODO Auto-generated method stub
int i = 1;
Integer j = new Integer(1);
System.out.print(i==j);//true
System.out.print(j.equals(i));//true
}

解决方案 »

  1.   

    这个叫自动拆箱,楼主如果想了解更多可以去google自动装拆箱。
    你程序中的 i==j 相当于 i==j.intValue()
      

  2.   

    autoboxing
    泛型里面也会有用到,方便
      

  3.   

    找到了,谢谢。
    自动装箱与拆箱:
    对基本数据类型来说:==比较的是两个变量的值
    int   i1 = 100;
    int   i2 = 100;
    i1==i2  //true对引用数据类型来说:==比较的是两个引用所指的地址(注意这两个引用类型的对象必须都是new出来的)
    Integer   i1 = new Ingeger(100);
    Integer   i 2= new Ingeger(100);
    i1==i2//false
    i1.eques(i2)//true
     
    当基本数据类型与引用数据类型比较时:
     int    i1  =  100;
    Integer  i2  = 100;
    i1 ==i2  //true    相当于 i2.intValue()  比较的是值
    i2.eques(i1)//true   比较值引用数据类型进行了自动拆箱,==比较的是值(在一个字节里),。
    Integer   i1  = 100;
    Integer   i2  = 100;
    i1==i2  //true但当不在一个字节里(超过127)
    Integer   i1  = 200;
    Integer   i2  = 200;
    i1==i2  //true
      

  4.   

    最后一个  ,但当不在一个字节里(超过127)
    Integer i1 = 200;
    Integer i2 = 200;
    i1==i2 //false