Java 各种布尔类型之间的差异?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3450117/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Differences among various bool types?
提问by sajjoo
What are the differences among bool, boolean and Boolean in Java/Android?
Java/Android 中的 bool、boolean 和 Boolean 有什么区别?
采纳答案by Thomas L?tzer
bool
does not seem to exist, at least I can't find references to it.
bool
似乎不存在,至少我找不到对它的引用。
boolean
is a primitive boolean type, notan object.
boolean
是原始布尔类型,而不是对象。
Boolean
is the wrapper object for a boolean
.
Boolean
是 a 的包装对象boolean
。
回答by Buhake Sindi
boolean
is a java primitive type. It only accepts true
or false
(which are declared constants in java).
boolean
是一个java原始类型。它只接受true
或false
(在java中声明的常量)。
Booleanis a Serializable wrapper of boolean
primitive type. From the JDK....
Boolean是boolean
原始类型的 Serializable 包装器。从 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 isboolean
.
的
Boolean
类包装在一个对象基本布尔型的值。Boolean 类型的对象包含一个类型为 的字段boolean
。
bool
doesn't exist in java, but it does in Android as R.bool
.
bool
在 Java 中不存在,但在 Android 中作为R.bool
.
回答by Md Abdul Shahed
The boolean data type indicates whether the value of an expression is either true or false. Therefore, a variable or expression which is declared as boolean type can use these two keywords. Syntax : boolean var_name; Example : boolean a; a=true; Or a=false;
布尔数据类型指示表达式的值是真还是假。因此,声明为布尔类型的变量或表达式可以使用这两个关键字。语法:boolean var_name; 示例:布尔值a;a=真;或 a=false;