私のクラスの1つでequalsプロパティをオーバーライドする場合、そのように実装することは可能ですか?識別子などの問題のプロパティは、String、boolean、Date、Set、またはLinkedHashSetである可能性があります
public boolean equals(Object obj)
{
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
if (!compareProperty(identifier, other.getIdentifier())) return false;
//Continue for all properties
}
//Compares any two objects
private boolean compareProperty(Object sourceObject, Object testObject)
{
if (sourceObject == null)
{
if (testObject != null)
return false;
}
else if(!sourceObject.equals(testObject))
{
return false;
}
return true;
}
なぜまたはなぜそうではないのですか?