我有以下类:
public class Sample implements java.io.Serializable{
//POJO with two fields and getters/setters
private String name;
private Integer id;
//This POJO does not override equals() and hashCode()
}
public class B{
private Sample sample;
//here i need override hashcode and equals() based on **sample** property.
}
当我尝试在B类中重写equals()和hashCode()方法时,在Eclipse中出现了以下错误:
现在我该如何比较两个基于Sample属性是否相等的B实例?我不能修改Sample类。字段类型com.mypackage.Sample没有实现hashCode()和equals()方法-生成的代码可能无法正常工作。