Hi,
I have a class Range with 2 fields (starts and ends), it overrides equals() method:
The class is extended by 2 other classes - Gap and Task which does not overrides equals().
In this example Task equals Gap with the same starts and ends fields... :/.
What are the solutions (besides overriding equals method in Task and Gap or comparing getClass() (if(! (this.getClass( ).equals(o.getC lass()))) return false) in the Range.equals() method) to avoid it?
Thanks in advance,
Etam.
I have a class Range with 2 fields (starts and ends), it overrides equals() method:
Code:
public boolean equals(Object o) {
if(this == o)
return true;
if(o == null)
return false;
if(! (o instanceof Range))
return false;
Range r = (Range) o;
if(this.starts.equals(r.starts) && this.ends.equals(r.ends))
return true;
return false;
}
In this example Task equals Gap with the same starts and ends fields... :/.
What are the solutions (besides overriding equals method in Task and Gap or comparing getClass() (if(! (this.getClass( ).equals(o.getC lass()))) return false) in the Range.equals() method) to avoid it?
Thanks in advance,
Etam.
Comment