开发者

Differences among various bool types?

What are the differences among bool, boolean and Boolean in 开发者_如何学运维Java/Android?


bool does not seem to exist, at least I can't find references to it.

boolean is a primitive boolean type, not an object.

Boolean is the wrapper object for a boolean.


boolean is a java primitive type. It only accepts true or false (which are declared constants in java).

Boolean is a Serializable wrapper of boolean primitive type. From the JDK....

The Boolean class wraps a value of the primitive type boolean in an object. An object of type Boolean contains a single field whose type is boolean.

bool doesn't exist in java, but it does in Android as R.bool.


boolean is a primitive boolean type and occupies less memory. Boolean is the wrapper object for a boolean which introduced in JDK 1.5.

  1. Suppose you have a service API which will execute a query and get the data from multiple tables.
  2. After that this data is to be manipulated and converted into the json object.
  3. During this conversion, it ight be possible that some boolean field may have 'NULL' as value.
  4. While receiving it as a response, you will definately parse it into an object.
  5. This automatic conversion may fail if your conversion logic will try to parse Boolean 'NULL' value into boolean primitive variable because boolean can't accept 'NULL' values.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜