Possible Duplicate:
Why is Java's default value for Boolean set to true?可能重复:为什么Java的布尔值设置为true?
What is the default value of Boolean
(primitive wrapper) in Java?
在Java中,布尔(原语包装器)的默认值是什么?
7 个解决方案
#1
374
The default value for a Boolean
(object) is null
.
The default value for a boolean
(primitive) is false
.
布尔(对象)的默认值为空。布尔(原语)的默认值为false。
#2
358
The default value any Object reference is null
默认值任何对象引用都为空。
The default value for a boolean
is false.
布尔值的默认值为false。
#4
13
If you need to ask then you need to explicitely initialize your fields/variables.
如果你需要问,那么你需要显式地初始化你的字段/变量。
Because if you have to look it up, then chances are someone else needs to do that too.
因为如果你一定要查的话,很有可能其他人也需要查。
The value for a primtive boolean is false as can be seen here
primtive boolean的值为false,可以在这里看到
As mentioned by others the value for a Boolean will be null by default.
正如其他人所提到的,默认情况下布尔值的值为null。
#5
6
An uninitialized Boolean member (actually a reference to an object of type Boolean) will have the default value of null
.
未初始化的布尔成员(实际上是布尔类型对象的引用)的默认值为null。
#6
6
Boolean is an Object. So if it's an instance variable it will be null. If it's declared within a method you will have to initialize it, or there will be a compiler error.
布尔是一个对象。如果它是一个实例变量,它将是空的。如果在方法中声明它,您将不得不初始化它,否则会出现编译错误。
If you declare as a primitive i.e. boolean. The value will be false by default if it's an instance variable (or class variable). If it's declared within a method you will still have to initialize it to either true or false, or there will be a compiler error.
如果声明为一个原语,即布尔。如果是实例变量(或类变量),则默认值为false。如果在方法中声明它,您仍然需要将它初始化为true或false,否则会出现编译错误。
#7
4
There is no default. Boolean must be constructed with a boolean or a string. If the object is unintialized, it would point to null.
没有违约。布尔值必须用布尔值或字符串来构造。如果对象没有被初始化,它将指向null。
http://download.oracle.com/javase/6/docs/api/java/lang/Boolean.html
http://download.oracle.com/javase/6/docs/api/java/lang/Boolean.html
#1
374
The default value for a Boolean
(object) is null
.
The default value for a boolean
(primitive) is false
.
布尔(对象)的默认值为空。布尔(原语)的默认值为false。
#2
358
The default value any Object reference is null
默认值任何对象引用都为空。
The default value for a boolean
is false.
布尔值的默认值为false。
#3
#4
13
If you need to ask then you need to explicitely initialize your fields/variables.
如果你需要问,那么你需要显式地初始化你的字段/变量。
Because if you have to look it up, then chances are someone else needs to do that too.
因为如果你一定要查的话,很有可能其他人也需要查。
The value for a primtive boolean is false as can be seen here
primtive boolean的值为false,可以在这里看到
As mentioned by others the value for a Boolean will be null by default.
正如其他人所提到的,默认情况下布尔值的值为null。
#5
6
An uninitialized Boolean member (actually a reference to an object of type Boolean) will have the default value of null
.
未初始化的布尔成员(实际上是布尔类型对象的引用)的默认值为null。
#6
6
Boolean is an Object. So if it's an instance variable it will be null. If it's declared within a method you will have to initialize it, or there will be a compiler error.
布尔是一个对象。如果它是一个实例变量,它将是空的。如果在方法中声明它,您将不得不初始化它,否则会出现编译错误。
If you declare as a primitive i.e. boolean. The value will be false by default if it's an instance variable (or class variable). If it's declared within a method you will still have to initialize it to either true or false, or there will be a compiler error.
如果声明为一个原语,即布尔。如果是实例变量(或类变量),则默认值为false。如果在方法中声明它,您仍然需要将它初始化为true或false,否则会出现编译错误。
#7
4
There is no default. Boolean must be constructed with a boolean or a string. If the object is unintialized, it would point to null.
没有违约。布尔值必须用布尔值或字符串来构造。如果对象没有被初始化,它将指向null。
http://download.oracle.com/javase/6/docs/api/java/lang/Boolean.html
http://download.oracle.com/javase/6/docs/api/java/lang/Boolean.html