aboutsummaryrefslogtreecommitdiff
path: root/website-old/features/experimental/FieldDefaults.html
blob: a253198b80dec4d4867441ec2efdef061c826a68 (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<!DOCTYPE html>
<html><head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<link rel="stylesheet" type="text/css" href="../../logi/reset.css" />
	<link rel="stylesheet" type="text/css" href="../features.css" />
	<link rel="shortcut icon" href="../../favicon.ico" type="image/x-icon" />
	<meta name="description" content="Spice up your java" />
	<title>EXPERIMENTAL – @FieldDefaults</title>
</head><body><div id="pepper">
	<div class="minimumHeight"></div>
	<div class="meat">
		<div class="header"><a href="../../index.html">Project Lombok</a></div>
		<h1>@FieldDefaults</h1>
		<div class="byline">New default field modifiers for the 21st century.</div>
		<div class="since">
			<h3>Since</h3>
			<p>
				@FieldDefaults was introduced as experimental feature in lombok v0.11.4.
			</p>
		</div>
		<div class="experimental">
			<h3>Experimental</h3>
			<p>
			Experimental because:
			<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.
		</div>
		<div class="overview">
			<h3>Overview</h3>
			<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><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>
		</div>
		<div class="snippets">
			<div class="pre">
				<h3>With Lombok</h3>
				<div class="snippet">@HTML_PRE@</div>
			</div>
			<div class="sep"></div>
			<div class="post">
				<h3>Vanilla Java</h3>
				<div class="snippet">@HTML_POST@</div>
			</div>
		</div>
		<div style="clear: left;"></div>
		<div class="overview confKeys">
			<h3>Supported configuration keys:</h3>
			<dl>
			<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.fieldDefaults.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>
			</dl>
		</div>
		<div class="overview">
			<h3>Small print</h3><div class="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>
			</div>
		</div>
		<div class="footer">
			<a href="index.html">Back to experimental features</a> | <a href="ExtensionMethod.html">Previous feature (@ExtensionMethod)</a> | <a href="Delegate.html">Next feature (@Delegate)</a><br />
			<a href="../../credits.html" class="creditsLink">credits</a> | <span class="copyright">Copyright &copy; 2009-2016 The Project Lombok Authors, licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT license</a>.</span>
		</div>
		<div style="clear: both;"></div>
	</div>
</div>
<script type="text/javascript">
	var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
	document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
	try {
		var pageTracker = _gat._getTracker("UA-9884254-1");
		pageTracker._trackPageview();
	} catch(err) {}
</script>
</body></html>