使用Lombok,是否可以指定一个arg构造函数?
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.
@requiredArgsConstructor class MyClass { private String param; private Integer count = -1; }
原文地址:https://www.jb51.cc/java/127973.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。