Path: csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Robert Klemme Newsgroups: comp.lang.java.programmer Subject: Re: Why not String compare? Date: Wed, 31 Aug 2016 19:24:03 +0200 Lines: 31 Message-ID: References: <33463070-424f-4fb0-956b-2849f1a400eb@googlegroups.com> <1c9ad1a1-ee44-4a9f-a307-1dab14c4a921@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net +yEKzzopRXH4w9pjnmEMjgI3JA2TPFBBgbpJ+wi7Fy5G1Yb7o= Cancel-Lock: sha1:/MeoAdSnPgiVL7jGu3LdvWd/3a8= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 In-Reply-To: Xref: csiph.com comp.lang.java.programmer:35527 On 31.08.2016 11:45, Andreas Leitgeb wrote: > Robert Klemme wrote: >> The implementor must ensure sgn(x.compareTo(y)) == -sgn(y.compareTo(x)) >> for all x and y. (This implies that x.compareTo(y) must throw an >> exception iff y.compareTo(x) throws an exception.) > > An equivalent "symmetry" could be expected from .equals, but isn't. Not necessarily since the underlying concept is different - equivalence relation vs. total order. You can reasonably say "that nothing is not equivalent to myself" while from "not equivalent" nothing follows for order. And btw. the concept of treating null special is quite common, for example with RDBMS. > It's not "symmetry" as such, that implied the requirement. It was > just pragmatically defined so for .compareTo while not for .equals. Well, but that is the contract. And I can see some sense in this. > Any usecase for including null into the natural ordering of certain > Comparable objects is just flawed. There, now you said it yourself. :-) Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/