如下代码,Long 和Integer 进行比较:
Integer aa = 1; Long bb= 1L; System.out.println(aa.equals(bb));
输出为:false
查看Integer 的equals 方法
public boolean equals(Object obj) { if (obj instanceof Integer) { return value == ((Integer)obj).intValue(); } return false; }
equals方法,首先要判断类型是否相同,重写的时候也应该考虑这一点
这是基础啊,别再忘了。。。