Path: csiph.com!feeder.erje.net!2.eu.feeder.erje.net!newsfeed.kamp.net!newsfeed.kamp.net!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: Fri, 2 Sep 2016 18:29:26 +0200 Lines: 42 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 dIy4d6E8jz5XuE1itlA0+gyU4fUhBUeB4uTCM0CvOeUfp3So4= Cancel-Lock: sha1:rlELEN53v1+OkttdKxSfCAxMNt0= 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:35534 On 01.09.2016 12:17, Andreas Leitgeb wrote: > Robert Klemme wrote: >> 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 > > That's not the point. If it *was* about symmetry (or anti- for compareTo) > then both compareTo and equals would have to throw NPE for null argument, > because obviously both throw NPE when called on a null reference. Symmetry is not a value in itself, right? The point is that for different concepts (equivalence vs. total order) the requirement for symmetry can also be different. Both are too unrelated to require their implementations to behave identical with regard to exceptions and symmetry. >> You can reasonably say "that nothing is not equivalent to myself" > > If symmetry really was the requirement, then it would need to > include symmetry to null.equals(...). It isn't, though. > > That .compareTo(null) throws NPE is *not* "for symmetry", but for > a design decision, which defined compareTo to be NPE-symmetric. > For equals a different decision was made. And both these decisions > still make sense. Absolutely. > I think, we're in "violent agreement" here, anyway. :-) Yes. I think we've reached state of hair splitting. Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/