I am using Lombok in a spring boot project with Maven. My IDE is vscode
I tried using Lombok annotators to create a class like so:
@Getter
@AllArgsConstructor
public class FooModel {
private String name;
}
And it worked fine. However, when I tried to switch to the @Data annotation instead, I got an error:
@Data
public class FooModel {
private String name;
}
The constructor FooModel(String) is undefined
I thought the @Data annotation was supposed to build the constructor for me. What's going on here?
CodePudding user response:
@Datais a convenient shortcut annotation that bundles the features of@ToString,@EqualsAndHashCode,@Getter/@Setterand@RequiredArgsConstructortogether.
Because your name field isn't final, it isn't a "required arg". Either make it final so that @RequiredArgsConstructor takes it into account, or keep your @AllArgsConstructor annotation alongside @Data.
