Sorry, I'm making a real start in Java, so this question is probably already answered, but I was not able. to find it. I want to do something similar (I already know that you can not actually surrender operator):
bool operator & lt; (MyClass a, MyClass b) {/ * code * /} What is the syntax required to do this, and where do I define this operation?
yes MyClass apply comparative : Class Meals applies Comparable & lt; MyClass & gt; {Compare Public Entry (MyClass Other) {// returns a negative number if it & lt; Other, 0 if it == Other, // If it & gt; Other}} and then a & lt; B , a.compareTo (b) & lt; 0 .
MyClass & gt; Comparator = new comparison & lt; MyClass & gt; () {Public int comparison (MyClass a, MyClass b) {// same rules}};
and then comparator.compare (a, b) & lt; 0 .
No comments:
Post a Comment