File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Qn about boolean & operator

 
Kishore Dandu
Ranch Hand
Posts: 1934
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does it work similar to using &&.

I mean is a & b same as a&&b; in case both a, b are boolean
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, in the case of &&, if expression a is false then expression b will not even be evaluated.
 
Mike Gershman
Ranch Hand
Posts: 1272
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A common use of &&:

if ( myObject != null && myObject.isSomething() ) { ... }

if myObject contains null, you are guaranteed that no attempt will be made to invoke myObject.isSomething()

If you use & instead of && in those circumstances, you'd get a NullPointerException
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic