Skip to content
Advertisement

NoArgsConstructor and AllArgsConstructor annotation on Child class for parent constructors

Hello to the overflow community, I am struggling on an inheritance problem with Lombok. I’m trying to add both annotation @AllArgsConstructor and @NoArgsConstructor on a child class in order to use the parent lombok constructors but got the error “Duplicate method Child()”.

Parent class:

JavaScript

Child class:

JavaScript

The error message:

Duplicate method Child() in type Child Java(67109219)

Thanks to the @rentox98 reply, I understand that the ArgsConstructor on my child class would always be empty, resulting on two identical constructors.

Is there a Lombok way to generate ArgsConstructors on my child class based on the parent lombok ArgsConstructors ?

Advertisement

Answer

In your Child class you have no attributes, so @NoArgsConstructor and @AllArgsConstructor are the same and the error occurs.


If you wanted an all-args constructor that would pass the properties to the parent class’s all-args constructor, you’d have to write it yourself; Lombok won’t generate it.

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement