4

Is renaming extends Comparable[A] to extends Ordered[A] and renaming def compareTo to def compare enough or is there anything I should take care of?

1 Answer 1

7

You're correct, that's all you need to do. The other methods in Ordered will use their default implementations, which go as follows:

def <  (that: A): Boolean = (this compare that) <  0
def >  (that: A): Boolean = (this compare that) >  0
def <= (that: A): Boolean = (this compare that) <= 0
def >= (that: A): Boolean = (this compare that) >= 0
def compareTo(that: A): Int = compare(that)

The only thing that doesn't have a default implementation in Ordered is compare, which you'll be defining using your old compareTo method. Should work, provided the above is what you want for your other comparisons.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.