[code="java"]
public class A
{
public static void main(String... args)
{
int s = 4;
Integer int1 = s;
Integer int2 = s;
System.out.println(int1 == int2);
int ss = 444;
Integer int3 = ss;
Integer int4 = ss;
System.out.println(int3 == int4);
}
}
[/code]
为何第一个为true第二个为false
Integer 是对象 == 是判断两个对象的内存地址是否相等, 但是java编译器在编译时为了加快效率,有对象缓存的概念,Integer,Long在1到127中会缓存,不会去new,所以是同一个对象,但是楼主你这样
Integer in1=new Integer("2");
Integer in2=new Integer("2");
System.out.println(in1==in2);
就会返回false