diff options
author | Reinier Zwitserloot <reinier@zwitserloot.com> | 2017-05-08 21:28:02 +0200 |
---|---|---|
committer | Reinier Zwitserloot <reinier@zwitserloot.com> | 2017-05-29 21:02:54 +0200 |
commit | 8b7a7cbc813653a3248d6cf3a7779e220957bc85 (patch) | |
tree | b9acfb9d68c6866acc3cfb9ee59d72ff43f1ebc3 /website/templates/features/Value.html | |
parent | 72fd50b9f1db1ab6bfc1753ba6a1e686a2f0f22c (diff) | |
download | lombok-8b7a7cbc813653a3248d6cf3a7779e220957bc85.tar.gz lombok-8b7a7cbc813653a3248d6cf3a7779e220957bc85.tar.bz2 lombok-8b7a7cbc813653a3248d6cf3a7779e220957bc85.zip |
The great rename: the old ‘website’ is now ‘website-old’, and ‘website2’ is now ‘website’.
Diffstat (limited to 'website/templates/features/Value.html')
-rw-r--r-- | website/templates/features/Value.html | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/website/templates/features/Value.html b/website/templates/features/Value.html new file mode 100644 index 00000000..fdad0e12 --- /dev/null +++ b/website/templates/features/Value.html @@ -0,0 +1,50 @@ +<#import "_features.html" as f> + +<@f.scaffold title="@Value" logline="Immutable classes made very easy."> + <@f.history> + <p> + <code>@Value</code> was introduced as experimental feature in lombok v0.11.4. + </p><p> + <code>@Value</code> no longer implies <code>@Wither</code> since lombok v0.11.8. + </p><p> + <code>@Value</code> promoted to the main <code>lombok</code> package since lombok v0.12.0. + </p> + </@f.history> + + <@f.overview> + <p> + <code>@Value</code> is the immutable variant of <a href="/features/Data"><code>@Data</code></a>; all fields are made <code>private</code> and <code>final</code> by default, and setters are not generated. The class itself is also made <code>final</code> by default, because immutability is not something that can be forced onto a subclass. Like <code>@Data</code>, useful <code>toString()</code>, <code>equals()</code> and <code>hashCode()</code> methods are also generated, each field gets a getter method, and a constructor that covers every argument (except <code>final</code> fields that are initialized in the field declaration) is also generated. + </p><p> + In practice, <code>@Value</code> is shorthand for: <code>final @ToString @EqualsAndHashCode @AllArgsConstructor @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) @Getter</code>, except that explicitly including an implementation of any of the relevant methods simply means that part won't be generated and no warning will be emitted. For example, if you write your own <code>toString</code>, no error occurs, and lombok will not generate a <code>toString</code>. Also, <em>any</em> explicit constructor, no matter the arguments list, implies lombok will not generate a constructor. If you do want lombok to generate the all-args constructor, add <code>@AllArgsConstructor</code> to the class. You can mark any constructor or method with <code>@lombok.experimental.Tolerate</code> to hide them from lombok. + </p><p> + It is possible to override the final-by-default and private-by-default behavior using either an explicit access level on a field, or by using the <code>@NonFinal</code> or <code>@PackagePrivate</code> annotations.<br /> + It is possible to override any default behavior for any of the 'parts' that make up <code>@Value</code> by explicitly using that annotation. + </p> + </@f.overview> + + <@f.snippets name="Value" /> + + <@f.confKeys> + <dt> + <code>lombok.value.flagUsage</code> = [<code>warning</code> | <code>error</code>] (default: not set) + </dt><dd> + Lombok will flag any usage of <code>@Value</code> as a warning or error if configured. + </dd><dt> + <code>lombok.val.flagUsage</code> = [<code>warning</code> | <code>error</code>] (default: not set) + </dt><dd> + Lombok will flag any usage of <code>val</code> as a warning or error if configured. + </dd> + </@f.confKeys> + + <@f.smallPrint> + <p> + Look for the documentation on the 'parts' of <code>@Value</code>: <a href="/features/ToString"><code>@ToString</code></a>, <a href="/features/EqualsAndHashCode"><code>@EqualsAndHashCode</code></a>, <a href="/features/Constructor"><code>@AllArgsConstructor</code></a>, <a href="/features/experimental/FieldDefaults"><code>@FieldDefaults</code></a>, and <a href="/features/GetterSetter"><code>@Getter</code></a>. + </p><p> + For classes with generics, it's useful to have a static method which serves as a constructor, because inference of generic parameters via static methods works in java6 and avoids having to use the diamond operator. While you can force this by applying an explicit <code>@AllArgsConstructor(staticConstructor="of")</code> annotation, there's also the <code>@Value(staticConstructor="of")</code> feature, which will make the generated all-arguments constructor private, and generates a public static method named <code>of</code> which is a wrapper around this private constructor. + </p><p> + <code>@Value</code> was an experimental feature from v0.11.4 to v0.11.9 (as <code>@lombok.experimental.Value</code>). It has since been moved into the core package. The old annotation is still around (and is an alias). It will eventually be removed in a future version, though. + </p><p> + It is not possible to use <code>@FieldDefaults</code> to 'undo' the private-by-default and final-by-default aspect of fields in the annotated class. Use <code>@NonFinal</code> and <code>@PackagePrivate</code> on the fields in the class to override this behaviour. + </p> + </@f.smallPrint> +</@f.scaffold> |