Tom Hawtin <usenet@tackline.plus.com> writes:
It's a bad idea to use natural ordering for presentation. Use a
Comparator instead.
Strange when the Javadocs for Comparable and Comparator seem almost
copy-pasted... so Comparator's intent seems to be an "outside" version
of Comparable.
If you put your customers in a TreeSet (with natural ordering), you
wouldn't get them all back out.
Well, a TreeSet with a Comparator has the same issue.
The natural ordering of named objects would seem to be alphabetical.
It's not the sorting algorithm's problem that people foolishly are
allowed to have the same name. :)
But a fix would be to assume this in the sorting and thus add a
"unseen" sorting key, like the customer number in my example.
How about the numeric case. Should BigDecimal 5 with a scale of 3 be
having the same magnitude, but that round differently.