=\"?This" />
开发者

Java relational operators

开发者 https://www.devze.com 2023-03-14 15:05 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消