且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

lombok中的默认值。如何使用构造函数和构建器初始化默认值

更新时间:2023-10-10 07:55:46

我的猜测是不可能的(没有删除代码)。但是你为什么不实现你需要的构造函数呢? Lombok旨在让您的生活更轻松,如果某些东西不能与Lombok一起使用,只需按照老式方式进行。

My guess is that it's not possible (without having delomboked the code). But why don't you just implement the constructor you need? Lombok is meant to make your life easier, and if something won't work with Lombok, just do it the old fashioned way.

@Data
@Builder
@AllArgsConstructor
public class UserInfo { 
    private int id;
    private String nick;
    @Builder.Default
    private boolean isEmailConfirmed = true;

    public UserInfo(){
        isEmailConfirmed = true;
    }
}

控制台输出:

ui: true
ui2: true