Is there a plug in that supports compare operations on a custom object?
I would like to use this:
class MyTemperatureObject implements Comparable<MyTemperatureObject> {
...
@Override
public int compareTo(MyTemperatureObject object) {
return getValue().compareTo(object.getValue());
}
}
MyTemperatureObject a;
MyTemperatureObject b;
if (a < b){
...
}
This gives the compile error:
Operator '<' cannot be applied to MyTemperatureObject
But I think that the compiler can use the Comparable interface to evaluate this. Or is there maybe a reason that this is not possible or not wisely to do this.
I know that I can use the compareTo function
a.compareTo(b) < 0
But I think this is better readable/understandable
a < b