I created an object HashSet, and the value is an object (Triple) which is my own class. But I get a strange thing, when there are two equal objects on my HashSet, is it possible? Here is my overriding method for the equals in the class Triple
@Override
public boolean equals(Object other){
if (other == null) return false;
if (other == this) return true;
if (this.getClass() != other.getClass()) return false;
Triple otherTriple = (Triple)other;
if(otherTriple.getSubject().equals(getSubject()) &&
otherTriple.getPredicate().equals(getPredicate()) &&
otherTriple.getObject().equals(getObject()))
return true;
return false;
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…