Is there a way to set 'not null' for all params of @AllArgsConstructor (lombok)

后端 未结 2 1102
無奈伤痛
無奈伤痛 2021-01-19 23:22

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

相关标签:
2条回答
  • 2021-01-20 00:01

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

    0 讨论(0)
  • 2021-01-20 00:07

    @RequiredArgsConstructor

    Generates a constructor with required arguments. Required arguments are final fields and fields with constraints such as @NonNull. Complete documentation is found at the project lombok features page for @Constructor . Even though it is not listed, this annotation also has the onConstructor parameter. See the full documentation for more details.

    0 讨论(0)
提交回复
热议问题