In another question, my code has such a equals
method:
public class Length {
private final double value;
private final Unit unit;
public Length(double value, Unit unit) {
this.value = value;
this.unit = unit;
}
@Override
public boolean equals(Object obj) {
Length length = (Length) obj;
return this.unit.toMM(this.value) == length.unit.toMM(length.value);
}
}
I want to compare two Length
s, they are equal to each other if they can be converted to the same unit with same length value
@weston gives me some very good explanations under this answer about why I should not use equals
here, but I still not quite clear.