I am working with a Location object from another closed API and it already has a toString() method that returns a String. I just want an implicit function that can compare two Location instances by comparing their toString() values. So I will be able to go
val L1 = new Location(**Parameters for Location**)
val L2 = new Location(**Parameters for Location**)
if (L2 > L1) { **do something** }
Consider providing an implicit conversion to an instance of type
Ordered:In this way, you automatically get all the other comparison methods
<=,<,>=,>for free.As @AlexeyRomanov has pointed out, it is usually preferable to have an implicit
Orderingin scope, because for exampleList.sortrequires it as an implicit argument. The implementation would be even shorter than forOrdered:This would allow us to compare the
Locationvalues like this: