有没有办法为@AllArgsConstructor的所有参数设置'not null'(lombok) [英] Is there a way to set 'not null' for all params of @AllArgsConstructor (lombok)

查看:123
本文介绍了有没有办法为@AllArgsConstructor的所有参数设置'not null'(lombok)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的课程中使用 @AllArgsConstructor 批注,并希望确保参数不为null.有没有办法修改此批注以使其成为可能,或者我应该实现承包商?谢谢

I'm using the @AllArgsConstructor annotation in my class and want to be sure that arguments will be not null. Is there a way to modify this annotation to make this possible, or I should implement constractor? Thanks

@Getter
@Setter
@ToString
@AllArgsConstructor
public class Contact {

    private String name;
    private String phoneNumber;

}

...

<lombok.version>1.16.18</lombok.version>

推荐答案

是的,您必须在此类字段上使用 @ NonNull ,这将导致在生成的构造函数中进行null检查.

Yes, you have to use @ NonNull on such fields, it will result in a null check in the generated constructor.

这篇关于有没有办法为@AllArgsConstructor的所有参数设置'not null'(lombok)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆