public class EncryptConfig { private Boolean enable; private String key; private String iv; private String salt; } 根据上述类写出可以通过build方法构造实例的代码
时间: 2024-03-09 07:45:27 浏览: 42
以下是可以通过build方法构造EncryptConfig实例的代码:
```
public class EncryptConfigBuilder {
private Boolean enable;
private String key;
private String iv;
private String salt;
public EncryptConfigBuilder() {}
public EncryptConfigBuilder withEnable(Boolean enable) {
this.enable = enable;
return this;
}
public EncryptConfigBuilder withKey(String key) {
this.key = key;
return this;
}
public EncryptConfigBuilder withIv(String iv) {
this.iv = iv;
return this;
}
public EncryptConfigBuilder withSalt(String salt) {
this.salt = salt;
return this;
}
public EncryptConfig build() {
EncryptConfig config = new EncryptConfig();
config.enable = enable;
config.key = key;
config.iv = iv;
config.salt = salt;
return config;
}
}
```
使用示例:
```
EncryptConfig config = new EncryptConfigBuilder()
.withEnable(true)
.withKey("my key")
.withIv("my iv")
.withSalt("my salt")
.build();
```
阅读全文