Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Loretta Carpenter   on Jan 10 In Java Category.

  
Question Answered By: Bradley Evans   on Jan 10

The problem  is that for conditional statements (like if, else etc.) in
java/C++, it does "Short-circuiting". i.e. This means that the expression will
be evaluated only until the truth or falsehood of the entire expression can be
unambiguously determined.

In ur case when, s = null;

a. if (s== null  || s.length()> 0),
Here s==null is TRUE, so s.length() is not evaluated.

b. if ( s!= null || s.length()> 0),
Here s!=null, this means the conditional statement can be true
if s.lenght()>0. But the time it evaluates s.lenght(), it finds
s is null and throws NPE.

Share: 

 

This Question has 1 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on java.lang.NullPointerException Or get search suggestion and latest updates.


Tagged: