What's the difference between boolean and Boolean in Java? [duplicate]
I'm not sure if the GWT factor makes a difference but in general:
boolean is a java primitive type whereas Boolean is an object/reference type that wraps a boolean
Converting between primitives and objects like this is known as boxing/unboxing.
Here is more info:
http://javaeye.wordpress.com/2008/06/17/boxing-and-unboxing-conversion/
Why box you ask?
http://java.sun.com/j2se/1.5.0/docs/guide/language/autoboxing.html
In Java, a boolean
is a literal true
or false
, while Boolean
is an object wrapper for a boolean
.
There is seldom a reason to use a Boolean
over a boolean
except in cases when an object reference is required, such as in a List
.
Boolean
also contains the static method parseBoolean(String s)
, which you may be aware of already.