From cb091204f4bfc7f9971fc296903f7bc2a163f085 Mon Sep 17 00:00:00 2001
From: Reinier Zwitserloot @Data generates all the boilerplate that is normally associated with simple POJOs
(Plain Old Java Objects) and beans: getters for all fields, setters for all non-final fields, and appropriate toString, equals
and hashCode implementations that involve the fields of the class. In addition, @Data generates a constructor that
- initialized all final fields.
+ initializes all final fields, as well as all non-final fields with no initializer that have been marked with @NonNull or @NotNull,
+ in order to ensure the field is never null.
@Data is like having implicit @ToString and @EqualsAndHashCode annotations on the class.
However, the parameters of @ToString and @EqualsAndHashCode (such as callSuper, includeFieldNames and
@@ -62,6 +63,12 @@
See the small print of @ToString, @EqualsAndHashCode and
@Getter / @Setter.
+
+ Any annotations named @NonNull or @NotNull (case insensitive) on a field are interpreted as: This field must not ever hold
+ null. Therefore, these annotations result in an explicit null check in the generated constructor for the provided field. Also, these
+ annotations (as well as any annotation named @Nullable) are copied to the constructor parameter, in both the true constructor and
+ any static constructor. The same principle applies to generated getters and setters (see the documentation for @Getter / @Setter)
+