sun.security.action 源码学习07 GetPropertyAction
阅读原文时间:2021年04月20日阅读:1

1. 源码

public class GetPropertyAction implements PrivilegedAction<String> {
    private String theProp;
    private String defaultVal;

    public GetPropertyAction(String var1) {
        this.theProp = var1;
    }

    public GetPropertyAction(String var1, String var2) {
        this.theProp = var1;
        this.defaultVal = var2;
    }

    public String run() {
        String var1 = System.getProperty(this.theProp);
        return var1 == null?this.defaultVal:var1;
    }
}

2. 测试

    @Test
    public void test03(){
        GetPropertyAction propertyAction = new GetPropertyAction("file.separator");
        System.out.println(propertyAction.run()); // result : \
    }
    @Test
    public  void test04(){
        GetPropertyAction propertyAction = new GetPropertyAction("a","ccc");
        System.out.println(propertyAction.run());
    }

手机扫一扫

移动阅读更方便

阿里云服务器
腾讯云服务器
七牛云服务器

你可能感兴趣的文章