Which is the 'correct' way to do this (if statement)

Posted by frinkz on Stack Overflow See other posts from Stack Overflow or by frinkz
Published on 2010-06-03T18:24:49Z Indexed on 2010/06/03 18:34 UTC
Read the original article Hit count: 168

Filed under:
|

I've got plenty of these lying around, and I'm wondering if I'm going to face any trouble - or performance problems.

I have method A:


MyClass monkey;
...
if(monkey != null) {
 ...
}

Or method B:


boolean hasMonkey; //This is set to TRUE when monkey is not null
MyClass monkey;
...
if(hasMonkey) {
 ...
}

On a functional level, they both do the same thing. Right now, I'm using method A. Is that a bad way of doing things? Which is going to perform better?

© Stack Overflow or respective owner

Related posts about java

Related posts about android