aboutsummaryrefslogtreecommitdiff
path: root/website2/templates/features/GetterLazy.html
diff options
context:
space:
mode:
Diffstat (limited to 'website2/templates/features/GetterLazy.html')
-rw-r--r--website2/templates/features/GetterLazy.html31
1 files changed, 31 insertions, 0 deletions
diff --git a/website2/templates/features/GetterLazy.html b/website2/templates/features/GetterLazy.html
new file mode 100644
index 00000000..b1f374a8
--- /dev/null
+++ b/website2/templates/features/GetterLazy.html
@@ -0,0 +1,31 @@
+<#import "_features.html" as f>
+
+<@f.scaffold title="@Getter(lazy=true)" logline="Laziness is a virtue!">
+ <@f.history>
+ <code>@Getter(lazy=true)</code> was introduced in Lombok v0.10.
+ </@f.history>
+
+ <@f.overview>
+ <p>
+ You can let lombok generate a getter which will calculate a value once, the first time this getter is called, and cache it from then on. This can be useful if calculating the value takes a lot of CPU, or the value takes a lot of memory. To use this feature, create a <code>private final</code> variable, initialize it with the expression that's expensive to run, and annotate your field with <code>@Getter(lazy=true)</code>. The field will be hidden from the rest of your code, and the expression will be evaluated no more than once, when the getter is first called. There are no magic marker values (i.e. even if the result of your expensive calculation is <code>null</code>, the result is cached) and your expensive calculation need not be thread-safe, as lombok takes care of locking.
+ </p>
+ </@f.overview>
+
+ <@f.snippets name="GetterLazy" />
+
+ <@f.confKeys>
+ <dt>
+ <code>lombok.getter.lazy.flagUsage</code> = [<code>warning</code> | <code>error</code>] (default: not set)
+ </dt><dd>
+ Lombok will flag any usage of <code>@Getter(lazy=true)</code> as a warning or error if configured.
+ </dd>
+ </@f.confKeys>
+
+ <@f.smallPrint>
+ <p>
+ You should never refer to the field directly, always use the getter generated by lombok, because the type of the field will be mangled into an <code>AtomicReference</code>. Do not try to directly access this <code>AtomicReference</code>; if it points to itself, the value has been calculated, and it is <code>null</code>. If the reference points to <code>null</code>, then the value has not been calculated. This behaviour may change in future versions. Therefore, <em>always</em> use the generated getter to access your field!
+ </p><p>
+ Other Lombok annotations such as <code>@ToString</code> always call the getter even if you use <code>doNotUseGetters=true</code>.
+ </p>
+ </@f.smallPrint>
+</@f.scaffold>