sun.security.action 源码学习07 GetPropertyAction

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

猜你喜欢

转载自blog.csdn.net/weixin_38389755/article/details/93743258