Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Eddie McNally's Jxam question...

 
Brett Hicks
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Question from the test...
Given the following code snippet:
String s = null;
Which of the following will throw NullPointerException...
1) if (( s!= null ) & ( s.length() > 0 ))
2) if (( s!= null ) && ( s.length() > 0 ))
3) if (( s!= null ) | ( s.length() > 0 ))
4) if (( s!= null ) | | ( s.length() > 0 ))
5) none of the above
The answer says that 1,2,3 & 4 will cause NullPointerExceptions.
Shouldn't number 2 short-circuit before it hits the s.length() statement, and thusly leave 1, 3 & 4 as the correct answers.

 
Nain Hwu
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Brett,
You are right - 2 will not cause NullPointerException.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic