62,612
社区成员
发帖
与我相关
我的任务
分享
public class Test {
Test test;
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((test == null) ? 0 : test.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Test other = (Test) obj;
if (test == null) {
if (other.test != null)
return false;
} else if (!test.equals(other.test))
return false;
return true;
}
}
if (obj == null)
return false;
这个有什么用?如果test是null,obj也是null不就是true了吗?(只是假设,这个时候用equals会异常)
Test other = (Test) obj;
if (test == null) {
if (other.test != null)
return false;
} else if (!test.equals(other.test))
return false;
这段...我不知道它是在比较什么...