Your class is equivalent to:
@Accessors(chain = true) @Data @NoArgsConstructor @AllArgsConstructor public class Answer<T> { private T data; }
Although, strictly speaking, this adds the toString , equals and hashCode methods to all variables. This can (and often) causes endless loops. Be very careful with @Data .
@Accessors(chain = true) does implementations of setter return this , in more detail here .
You can add some constructor annotations:
Unlike most other lombok annotations, the existence of an explicit constructor does not stop these annotations from creating your own constructor.
Please note that @Accessors is experimental, so you can change / rename it at some future point.
I prefer @Builder to @AllArgsConstructor , since it allows you to set only the required parameters, while all argument constructors are all or nothing, It also generates much more readable code, consider
new Thing(true, 1, 4, false, 4, 4.0)
Vs
new Thing.Builder(). setANamnedProperty(true). setAnotherNamnedProperty(1). .... build();
source share