From f8b3056dc4f61251aba7adf627c942c85e8618ca Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Sun, 1 Jun 2014 11:02:18 +0200 Subject: Fixed up and extended Tolerate with support for constructors, and added docs. --- website/features/Data.html | 29 ++++++----------------------- 1 file changed, 6 insertions(+), 23 deletions(-) (limited to 'website/features/Data.html') diff --git a/website/features/Data.html b/website/features/Data.html index 3ae03df1..c3d0a644 100644 --- a/website/features/Data.html +++ b/website/features/Data.html @@ -16,35 +16,18 @@

Overview

- @Data is a convenient shortcut annotation that bundles the features of @ToString, - @EqualsAndHashCode, @Getter / @Setter - and @RequiredArgsConstructor together: In other words, @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, and a constructor that - initializes all final fields, as well as all non-final fields with no initializer that have been marked with @NonNull, - in order to ensure the field is never null. + @Data is a convenient shortcut annotation that bundles the features of @ToString, @EqualsAndHashCode, @Getter / @Setter and @RequiredArgsConstructor together: In other words, @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, and a constructor that initializes all final fields, as well as all non-final fields with no initializer that have been marked with @NonNull, in order to ensure the field is never null.

- @Data is like having implicit @Getter, @Setter, @ToString, @EqualsAndHashCode and @RequiredArgsConstructor - annotations on the class. However, the parameters of these annotations (such as callSuper, includeFieldNames and - exclude) cannot be set with @Data. If you need to set non-default values for any of these parameters, just add those annotations - explicitly; @Data is smart enough to defer to those annotations. + @Data is like having implicit @Getter, @Setter, @ToString, @EqualsAndHashCode and @RequiredArgsConstructor annotations on the class. However, the parameters of these annotations (such as callSuper, includeFieldNames and exclude) cannot be set with @Data. If you need to set non-default values for any of these parameters, just add those annotations explicitly; @Data is smart enough to defer to those annotations.

- All generated getters and setters will be public. To override the access level, annotate the field or class with an explicit @Setter and/or - @Getter annotation. You can also use this annotation (by combining it with AccessLevel.NONE) to suppress generating a getter and/or setter - altogether. + All generated getters and setters will be public. To override the access level, annotate the field or class with an explicit @Setter and/or @Getter annotation. You can also use this annotation (by combining it with AccessLevel.NONE) to suppress generating a getter and/or setter altogether.

- All fields marked as transient will not be considered for hashCode and equals. All static fields will be - skipped entirely (not considered for any of the generated methods, and no setter/getter will be made for them). + All fields marked as transient will not be considered for hashCode and equals. All static fields will be skipped entirely (not considered for any of the generated methods, and no setter/getter will be made for them).

- If the class already contains a method with the same name as any method that would normally be generated, that method is not generated, and no warning or - error is emitted. For example, if you already have a method with signature void hashCode(int a, int b, int c), no int hashCode() - method will be generated, even though technically int hashCode() is an entirely different method. The same rule applies to the constructor (any explicit constructor will prevent @Data from generating one), - toString, equals, and all getters and setters. + If the class already contains a method with the same name and parameter count as any method that would normally be generated, that method is not generated, and no warning or error is emitted. For example, if you already have a method with signature equals(AnyType param), no equals method will be generated, even though technically it might be an entirely different method due to having different parameter types. The same rule applies to the constructor (any explicit constructor will prevent @Data from generating one), as well as toString, equals, and all getters and setters. You can mark any constructor or method with @lombok.experimental.Tolerate to hide them from lombok.

@Data can handle generics parameters for fields just fine. In order to reduce the boilerplate when constructing objects for classes with - generics, you can use the staticConstructor parameter to generate a private constructor, as well as a static method that returns a new - instance. This way, javac will infer the variable name. Thus, by declaring like so: @Data(staticConstructor="of") class Foo<T> { private T x;} - you can create new instances of Foo by writing: Foo.of(5); instead of having to write: new Foo<Integer>(5);. + generics, you can use the staticConstructor parameter to generate a private constructor, as well as a static method that returns a new instance. This way, javac will infer the variable name. Thus, by declaring like so: @Data(staticConstructor="of") class Foo<T> { private T x;} you can create new instances of Foo by writing: Foo.of(5); instead of having to write: new Foo<Integer>(5);.

-- cgit