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