Path: csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Robert Klemme Newsgroups: comp.lang.java.programmer Subject: Re: Type conversions with the empty string Date: Wed, 1 Feb 2017 00:01:48 +0100 Lines: 39 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Trace: individual.net pSurxnSzPKehmWSrNKCYwA5RKK7CAnpc9n9EXyJKcLxDgkZGc= Cancel-Lock: sha1:ze59dBdT/YjOpX8gxJbgY8sscvM= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.7.0 In-Reply-To: Xref: csiph.com comp.lang.java.programmer:36237 On 31.01.2017 03:29, Arne Vajh=C3=B8j wrote: > On 1/30/2017 1:08 PM, Stefan Ram wrote: >> Knute Johnson writes: >>> On 1/28/2017 07:43, Stefan Ram wrote: >>>> String.valueOf( 123 ) >>> You would prefer any of those over Integer.toString(123)? >> >> =C2=BBjava.lang.String.valueOf=C2=AB is the universal one-stop >> solution to convert anything into a string, including >> primitive values, class instances and even null! So it >> does not make me think. Whenever I want to convert anthing >> into a =C2=BBjava.lang.String=C2=AB instance, I use this. >> >> =C2=BBjava.lang.Integer.toString=C2=AB makes me thing about the type= >> of =C2=BB123=C2=AB and what the wrapper class of that type is, and >> whether it really has such a method (for example, the static >> =C2=BBjava.lang.Boolean.toString=C2=AB method is only @since 1.4, >> while =C2=BBjava.lang.Integer.toString=C2=AB is @since 1.0.) > > Well - some actually like that type strictness. Including me. > > If something should be an int, then I prefer a compile time > error if it suddenly is not an int any longer. Yes, but that would likely already be triggered by something more int=20 specific, e.g. an assignment or another method calls that needs to do=20 calculations with the value. For me, in this case also the Stefan's=20 argument wins - especially since this is an "uncontrolled" (as opposed=20 to using a format) conversion to String. Kind regards robert --=20 remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/