java 布尔类型的默认值
今天在看spring security源码时,有这么一段代码:
public UserDetails build() {
String encodedPassword = (String)this.passwordEncoder.apply(this.password);
return new User(this.username, encodedPassword, !this.disabled, !this.accountExpired, !this.credentialsExpired, !this.accountLocked, this.authorities);
}
其中!this.disabled
没有初始化就直接取反,想着打印输出下结果看下是什么?输出结果为true
.在这里取反,默认值是false
吗?
验证下:
public class PrimitiveTypeTest {
private boolean v;
public boolean getV(){
return this.v;
}
public static void main(String[] args) {
System.out.print(new PrimitiveTypeTest().getV());
}
}