• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java operators  RSS feed

 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://docstore.mik.ua/orelly/java-ent/jnut/ch02_05.htm

According to the above article , ||, && and ?: do not always evaluate all their operands.

Can i get some example statements for the above operators where all the operands are not evaluated.
 
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
// Example && : if first contition fails second never execute.

String string = null;
if(string != && string.length()>0 ) {
System.out.println("String is not empty");
}else {
System.out.println("String is not empty");
}


// Example & : even if first contition fails second will execute and a NullPointerException

String string = null;
if(string != & string.length()>0 ) {
System.out.println("String is not empty");
}else {
System.out.println("String is not empty");
}

 
Rajiv Chelsea
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Rob for the example
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


just make sure you never code like that
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!