According to the documentation, Lombok has 3 annotations for constructor generation:
@NoArgsConstructor - generates an empty constructor;@AllArgsConstructor - generates a constructor that initializes all
fields;@RequiredArgsConstructor - generates a constructor that
initializes only final fields.They all have an onConstructor property that allows you to specify the annotations with which the generated constructor should be marked.
According to the Javadoc, the syntax for this feature depends on JDK version (nothing we can do about that; it's to work around javac bugs).
Up to JDK7:
@NoArgsConstructor(onConstructor=@__({@AnnotationsGoHere}))
From JDK8:
@NoArgsConstructor(onConstructor_={@AnnotationsGohere}) // note the underscore after onConstructor
I am working on JDK8. However, only the JDK7 variant works for me, while the JDK8 variant does not work (a constructor without annotations is generated).
I checked on JDK11 - same result.
I check with Refactor -> Delombok -> @Constructors.
For example, like this:
@AllArgsConstructor(onConstructor = @__(@Deprecated))
public class SomeClass {
}
the following code is generated:
public class SomeClass {
@Deprecated
public SomeClass() {
}
}
But like so:
@AllArgsConstructor(onConstructor_ = @Deprecated)
public class SomeClass {
}
code like this is generated:
public class SomeClass {
public SomeClass() {
}
}
I noticed that the documentation on the Lombok site only contains a JDK7 style example.
The Javadoc is incorrect or am I doing something wrong?
I found, that it's not the Lombok's bug, it's Lombok IntelliJ plugin bug.
Constructor annotations add in compiled code.
Delombok tool of Lombok IntelliJ plugin incorrect convert Lombok's annotations to vanilla Java code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With