If bar can be null , and this is what you want to model in your class, I would use:
class foo { boolean bar; boolean isBar(){ return bar; } }
It is simpler, faster, and cannot have NullPointerException s.
If, however, null is a valid value and you need a model, you should use Boolean / Boolean .
Please note that your code is:
Boolean bar; boolean isBar() { return bar.booleanValue(); }
Or even an autoboxing option:
Boolean bar; boolean isBar() { return bar; }
... may throw NullPointerException s. Especially the last one is very confusing.
source share