aboutsummaryrefslogtreecommitdiff
path: root/website/templates/features/experimental/FieldDefaults.html
blob: 0d4cda9e14ef5bdeb5294eda4033d3fa5f62be11 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<#import "../_features.html" as f>

<@f.scaffold title="@FieldDefaults" logline="New default field modifiers for the 21st century.">
	<@f.history>
		<p>
			@FieldDefaults was introduced as experimental feature in lombok v0.11.4.
		</p>
	</@f.history>

	<@f.experimental>
		<ul>
			<li>
				New feature; unsure if this busts enough boilerplate.
			</li><li>
				Would be nice if you could stick this on the package-info.java package to set the default for all classes in that package.
			</li><li>
				Part of the work on @Value, which is experimental.
			</li>
		</ul>
		Current status: <em>positive</em> - Currently we feel this feature may move out of experimental status with no or minor changes soon.
	</@f.experimental>

	<@f.overview>
		<p>
			The <code>@FieldDefaults</code> annotation can add an access modifier (<code>public</code>, <code>private</code>, or <code>protected</code>) to each field in the annotated class or enum. It can also add <code>final</code> to each field in the annotated class or enum.
		</p><p>
			To add <code>final</code> to each (instance) field, use <code>@FieldDefaults(makeFinal=true)</code>. Any non-final field which must remain nonfinal can be annotated with <code>@NonFinal</code> (also in the <code>lombok.experimental</code> package).
		</p><p>
			To add an access modifier to each (instance) field, use <code>@FieldDefaults(level=AccessLevel.PRIVATE)</code>. Any field that does not already have an access modifier (i.e. any field that looks like package private access) is changed to have the appropriate access modifier. Any package private field which must remain package private can be annotated with <code>@PackagePrivate</code> (also in the <code>lombok.experimental</code> package).
		</p>
	</@f.overview>

	<@f.snippets name="experimental/FieldDefaults" />

	<@f.confKeys>
		<dt>
			<code>lombok.fieldDefaults.flagUsage</code> = [<code>warning</code> | <code>error</code>] (default: not set)
		</dt><dd>
			Lombok will flag any usage of <code>@FieldDefaults</code> as a warning or error if configured.
		</dd><dt>
			<code>lombok.fieldDefautls.defaultPrivate</code> = [<code>true</code> | <code>false</code>] (default: false)
		</dt><dd>
			(Since 1.16.8) If set to <code>true</code>, <em>every</em> field in <em>every</em> class or enum anywhere in the sources being compiled will be marked as <code>private</code> unless it has an explicit access modifier or the <code>@PackagePrivate</code> annotation, or an explicit <code>@FieldDefaults</code> annotation is present to override this config key.
		</dd><dt>
			<code>lombok.fieldDefaults.defaultFinal</code> = [<code>true</code> | <code>false</code>] (default: false)
		</dt><dd>
			(Since 1.16.8) If set to <code>true</code>, <em>every</em> field in <em>every</em> class or enum anywhere in the sources being compiled will be marked as <code>final</code> unless it has the <code>@NonFinal</code> annotation, or an explicit <code>@FieldDefaults</code> annotation is present to override this config key.
		</dd>
	</@f.confKeys>

	<@f.smallPrint>
		<p>
			Like other lombok handlers that touch fields, any field whose name starts with a dollar (<code>$</code>) symbol is skipped entirely. Such a field will not be modified at all.
		</p>
	</@f.smallPrint>
</@f.scaffold>