-4
if语句如何将Boolean
对象识别为boolean
?如:Java - if语句如何知道布尔对象的值?
Boolean b = new Boolean(true);
if(b){
System.out.println("true!");
} else {
System.out.println("false!");
}
这将打印正确的,但如何Boolean
认可?
if语句如何将Boolean
对象识别为boolean
?如:Java - if语句如何知道布尔对象的值?
Boolean b = new Boolean(true);
if(b){
System.out.println("true!");
} else {
System.out.println("false!");
}
这将打印正确的,但如何Boolean
认可?
请参阅https://docs.oracle.com/javase/tutorial/java/data/autoboxing.html –
顺便说一句如果您不希望值为空,您应该使用原语而不是包装器。 –