Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lombok: RequiredArgsConstructor not working

Tags:

It seems that @RequiredArgsConstructor not working in the code below. Why is it?

import java.io.Serializable;  import lombok.Data; import lombok.RequiredArgsConstructor;  @Data @RequiredArgsConstructor public class User implements Serializable {      private String username;      /*public User(String username) {         this.username = username;     }*/      private static final long serialVersionUID = 8043545738660721361L; } 

I get the error:

javax.faces.el.EvaluationException: java.lang.Error: Unresolved compilation problem:      The constructor User(String) is undefined 

For some reason seems it does work for other domain class in which no constructor defined but instead used the @RequiredArgsConstructor annotation.

like image 780
rozerro Avatar asked Jun 07 '16 05:06

rozerro


2 Answers

According to Documentation, Required arguments are final fields and fields with constraints such as @NonNull.

You need to make username as @NonNull

@NonNull private String username; 

And you need to make them final too.

like image 66
a3.14_Infinity Avatar answered Oct 20 '22 00:10

a3.14_Infinity


It's also worth noting for future readers that @Data also provides @RequiredArgsConstructor, so using both annotations isn't necessary :)

like image 37
adrianostgard Avatar answered Oct 20 '22 00:10

adrianostgard