Skip to content
Advertisement

Google Guice and Lombok – @AllArgsConstructor(onConstructor = @__(@Inject)) for abstract class

I find @AllArgsConstructor(onConstructor = @__(@Inject)) is helpful to keep code clean when working with Google Guice. I can save the constructor code. For example:

JavaScript

For abstract class, I’m able to use @Inject for constructor.

JavaScript

Is it possible to save the constructor code in ChildClass by using something like @AllArgsConstructor(onConstructor = @__(@Inject))?

Advertisement

Answer

No, it is not possible to define AllArgsConstructor in child class when there is parent constructor due to the limitation of Lombok (see this issue on GitHub and another answer on SO).

You could mix field/setter injection in parent with constructor injection in child, but I would advise to avoid it.

Advertisement