Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #36231
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Type conversions with the empty string |
| Date | 2017-01-30 21:27 -0500 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <o6oslq$1vpf$1@gioia.aioe.org> (permalink) |
| References | <emtpy-string-20170128143107@ram.dialup.fu-berlin.de> |
On 1/28/2017 8:43 AM, Stefan Ram wrote: > There are actually two ways to convert »123« to a string > that both involve the empty string: > > ""+123 > > and > > "".valueOf( 123 ) > > , and both are frowned upon! But real problems in software > enginnering involve architecture or "logical" errors, seldom > small-scale wordings. What is the worst thing that could > happen when someone uses one of those? (That a beginner reading > the source might become confused?) > > I'd say that > > "".valueOf( 123 ) > > is even more robust than > > String.valueOf( 123 ) > > because the former is still working when a file »String.class« > is found early enough in the class path. "".valueOf( 123 ) is rather bad. Calling static methods on instances is bad and may create warnings in many tools. And one should not chose coding style to defend against mixing up java.lang classes and user classes. Just avoid doing that. ""+123 is a lot more harmless. I would not use it. But given how common the construct is with a non-empty string, then I can see it with the empty string being that bad. Arne
Back to comp.lang.java.programmer | Previous | Next | Find similar | Unroll thread
Re: Type conversions with the empty string Arne Vajhøj <arne@vajhoej.dk> - 2017-01-30 21:27 -0500
csiph-web