If your program ever used the toString()
for lexical sorting using natural ordering in such a way that program execution depends on it, then it would be wise to override the default toString()
of the class that extended. You should in that case make the toString()
method final and clearly document that it is used for ordering.
It would however be much better to create another method returning a String
and create an ordering depending on that result, possibly by creating a specific Comparator
to do the sorting. See for instance the final method name()
used for enumerations in Java. In general it creates the same String as toString()
but it is still possible to perform ordering with it even if toString()
has been overridden.
If you use the last method, then the Ordering.usingToString()
would not be of much use of course.