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

前端之家收集整理的这篇文章主要介绍了java – Lombok:如何指定一个arg构造函数?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
使用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;
}
原文链接:https://www.f2er.com/java/127973.html

猜你在找的Java相关文章