简体   繁体   中英

Lombok Data annotation 'The constructor is undefined'

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?

@Data :

@Data is a convenient shortcut annotation that bundles the features of @ToString , @EqualsAndHashCode , @Getter / @Setter and @RequiredArgsConstructor together.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM