问题
@Data
@Builder
public class Demo {
@Tolerate
public Demo(){
}
private int type = 2;
private String url;
}
通过builder模式,如果不设置type,还指望它能够设置2,恐怕要令你失望了。
告警
Warning:(95, 30) java: @Builder will ignore the initializing expression entirely. If you want the initializing expression to serve as default, add @Builder.Default. if it is not supposed to be settable during building, add @Builder.Constant.
升级到最新版
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.16</version>
<scope>provided</scope>
</dependency>
使用@Builder.Default
@Builder.Default
private int type = 2;
这样就ok了。
doc
想获取最新内容,请关注微信公众号