...
CustomClass a = new CustomClass(x);
CustomClass b = new CustomClass(y);
if(a<b)...
I already played with comparable and comparator interface but with no luck.
[java] How to use = on custom classes?
Is it possible to use <>= on custom class?
for example
if ( a.equals(b) ) {};// Comparableif ( a.compareTo(b) < 0 ) {}
Relational operators
Note that you need to override and implement both of those methods according to their JavaDoc. That includes the hashCode() method.
Quote:Original post by Bojevnik
Is it possible to use <>= on custom class?
for example
...
CustomClass a = new CustomClass(x);
CustomClass b = new CustomClass(y);
if(a<b)...
I already played with comparable and comparator interface but with no luck.
using Java, AFAIK No.
you can hower create methods that does the comparison for you.
(Look at how the String class works for example)
Thank you both.
I knew about other methods, but this way just seemed faster to write(especialy by hand), too bad i cant be done.
I knew about other methods, but this way just seemed faster to write(especialy by hand), too bad i cant be done.
You can't do it in C++ by default either. You still have to write code to do it. You just get to write the code to use the mathematical signs instead of method calls.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement