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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 00:54:10  来源:igfitidea点击:

Differences among various bool types?

javaandroidboolean

提问by sajjoo

What are the differences among bool, boolean and Boolean in Java/Android?

Java/Android 中的 bool、boolean 和 Boolean 有什么区别?

采纳答案by Thomas L?tzer

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

bool似乎不存在,至少我找不到对它的引用。

booleanis a primitive boolean type, notan object.

boolean是原始布尔类型,而不是对象。

Booleanis the wrapper object for a boolean.

Boolean是 a 的包装对象boolean

回答by Buhake Sindi

booleanis a java primitive type. It only accepts trueor false(which are declared constants in java).

boolean是一个java原始类型。它只接受truefalse(在java中声明的常量)。

Booleanis a Serializable wrapper of booleanprimitive type. From the JDK....

Booleanboolean原始类型的 Serializable 包装器。从 JDK....

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

Boolean类包装在一个对象基本布尔型的值。Boolean 类型的对象包含一个类型为 的字段 boolean

booldoesn'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;