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());

    }  
} 

输出结果为false



来自为知笔记(Wiz)


posted on 2022-09-27 20:46  白衣风云  阅读(86)  评论(0编辑  收藏  举报

导航