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 08:17:35 +0200 Lines: 40 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 Uk2NrEmbE6RG1elVPCkggwJLF0dFPAjNsEsG3UzagSftm8hsM= Cancel-Lock: sha1:nkvKOJqPSutTiJ3E+lJTMkUjjqc= 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:35512 On 26.08.2016 22:55, Eric Douglas wrote: > On Friday, August 26, 2016 at 4:49:05 PM UTC-4, Robert Klemme wrote: >> On 26.08.2016 19:09, Eric Douglas wrote: >>> On Friday, August 26, 2016 at 12:49:32 PM UTC-4, Robert Klemme wrote: >>> http://docs.oracle.com/javase/8/docs/api/java/lang/Comparable.html#compareTo-T- >>>> >>> >>> What's your point? Did you read the question? >> >> Did you read the documentation? > Do you always answer a question with a question? Why should I? Seriously, that reply of mine was probably not the most inspired one. The intention was to suggest to read the documentation again. It's all in there, as others have pointed out already. > Yes, if you read my message, I am well aware the default for the > Comparable class is to throw NPE if you try to compareTo(null). I'm > asking why. This doesn't make sense. myString.compareTo(null) > should return 1, just as myString.equals(null) returns false. Why > shouldn't it make sense for everything to reutrn 1 (greater than) if > you compare to a null? Is there another value to pass into the > String.compareTo() to return the lowest possible String? This seems > dumb that everyone who wants to compare Strings has to null check > first. To me it makes perfectly sense, especially in light of this: 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.) Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/