ok this is really a simple question but I can't understand why my code does not work properly.
In a third part library I'm using, at a certain point something like this is done:
Object value = someValue;
Object compareValue = someOtherValue;
if(value.equals(compareValue))
// do something
now, my objects are instances of the same class, that override equals with the following contract:
@Override
public boolean equals(Object obj) {
the jvm anyway call the equals defined by the object class, giving me an unwanted behavior. How can I fix this? I repeat that the calling code is an external library that i can't modify.
edit: this is the full code of my class:
public class MissionPriorityResolutionCriteria implements ResolutionCriteria {
private Satellite prioritySatellite;
public MissionPriorityResolutionCriteria(Satellite prioritySatellite) {
this.prioritySatellite = prioritySatellite;
}
@Override
public int hashCode() {
int hash = 5;
hash = 53 * hash + (this.prioritySatellite != null ? this.prioritySatellite.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final MissionPriorityResolutionCriteria other = (MissionPriorityResolutionCriteria) obj;
if (this.prioritySatellite != other.prioritySatellite && (this.prioritySatellite == null || !this.prioritySatellite.equals(other.prioritySatellite))) {
return false;
}
return true;
}
public Satellite getPrioritySatellite() {
return prioritySatellite;
}
public void setPrioritySatellite(Satellite prioritySatellite) {
this.prioritySatellite = prioritySatellite;
}
public boolean apply(SRASolution s) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}
I know that he is calling the Object.equals because I stepped with the debugger... The equals implementation I'm using is generated by netbeans.