Generate constructor for required superfields

I have the following class:

import lombok.Getter; import lombok.RequiredArgsConstructor; @Getter @RequiredArgsConstructor public abstract class EmailData { private final Iterable<String> recipients; } 

and the following subclass:

 import lombok.Getter; @Getter public class PasswordRecoveryEmail extends EmailData { private final String token; } 

Is it possible to annotate PasswordRecoveryEmail in such a way that a constructor will be created for both the fields of the required class and the superclass?

+6
source share
1 answer

The @…Constructor annotations will not explicitly invoke the constructor, so they all rely on the default constructor to do the right thing. So no, you cannot convince Lombok to create these constructors for you.

The closest you can get is either:

  • Provide a default constructor (without arguments) in EmailData , which is protected , and assigns some reasonable value to recipients .
  • Write the require-args constructor for PasswordRecoveryEmail yourself.

Inheritance is often not fully covered by Lombok in my experience.

+1
source

Source: https://habr.com/ru/post/1014989/


All Articles