加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – Lombok:如何指定一个arg构造函数?

发布时间:2020-12-15 02:50:44 所属栏目:Java 来源:网络整理
导读:使用Lombok,是否可以指定一个arg构造函数? 我的目的是使用Lombok注释创建一个构造函数,如下所示. class MyClass { private String param; private Integer count; public MyClass(String param) { this.param = param; }} 解决方法 I didn’t find in docum
使用Lombok,是否可以指定一个arg构造函数?

我的目的是使用Lombok注释创建一个构造函数,如下所示.

class MyClass {
    private String param;
    private Integer count;

    public MyClass(String param) {
        this.param = param;
    }
}

解决方法

I didn’t find in documentation

怎么样:http://projectlombok.org/features/Constructor.html?

您必须初始化所有不应该是构造函数的变量.

@RequiredArgsConstructor generates a constructor with 1 parameter for each field that requires special handling. All non-initialized final fields get a parameter,as well as any fields that are marked as @NonNull that aren’t initialized where they are declared. For those fields marked with @NonNull,an explicit null check is also generated.

所以下面应该创建一个参数(param)构造函数:

@RequiredArgsConstructor class MyClass {
     private String param;
     private Integer count = -1;
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读