1,equals
@Test
public void test_equal(){
String a="1";
int b=1;
boolean result=a.equals(b);
System.out.println(result);
}
原因:equals 比较时自动把转化为包装类型了
运行结果是:
false
应该改为:
@Test
public void test_equal(){
String a="1";
int b=1;
boolean result=a.equals(String.valueOf(b));
System.out.println(result);
}
2,包装类型
@Test
public void test_equal2(){
Long a=229L;
Long b=229L;
System.out.println((a==b));
}
运行结果:false
@Test
public void test_equal2(){
Long a=29L;
Long b=29L;
System.out.println((a==b));
}
运行结果为:true
应该改为:
@Test
public void test_equal2(){
Long a=229L;
Long b=229L;
System.out.println((a.intValue()==b.intValue()));
}
原文地址:http://blog.csdn.net/hw1287789687/article/details/45916001