Thursday, 10 December 2015

true vs. Boolean.TRUE

I saw the following code below at my work, and it got me thoroughly confused. I found the statement above to be unnecessarily complicated.

private boolean useAsReferenceModel = Boolean.FALSE;

Boolean.FALSE returns a Boolean, which is a wrapper2 around the boolean primitive types.

So, in the example above, the Boolean wrapper is auto-unboxed3 to the primitive type false.

So, I changed the code to the simple and straightforward:
private boolean useAsReferenceModel = false;
Let us not make the world more complicated than it really is.


[1] StackOverflow - Java what is the difference between false and Boolean.FALSE
[2] Wikipedia - Primitive Wrapper Classes
[3] Oracle JavaDoc - Autoboxing and unboxing

1 comment:

  1. It is nice article to improve knowledge.thank you for sharing useful info
    web programming tutorial