Java relational operators
In Java, what interface(class) should a class implement(extend) in order to allow two in开发者_Python百科stances of the class to be comparable through relational operators like "<" or ">="?
This is not possible in Java.
If you want objects of your class to be comparable, implement Comparable
.
Java does not support operator overloading, so you're out of luck. Implementing java.lang.Comparable
or providing a java.util.Comparator
is what you're supposed to do.
精彩评论