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
96
97
98
99
100
101
102
103
|
<!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 - @Accessors</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>@Accessors</h1>
<div class="byline">A more fluent API for getters and setters.</div>
<div class="since">
<h3>Since</h3>
<p>
@Accessors was introduced as experimental feature in lombok v0.11.0.
</p>
</div>
<div class="experimental">
<h3>Experimental</h3>
<p>
Experimental because:
<ul>
<li>We may want to roll these features into a more complete property support concept.</li>
<li>New feature - community feedback requested.</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>@Accessors</code> annotation is used to configure how lombok generates and looks for getters and setters.
</p><p>
By default, lombok follows the <em>bean specification</em> for getters and setters: The getter for a field named <code>pepper</code>
is <code>getPepper</code> for example. However, some might like to break with the <em>bean specification</em> in order to end up with
nicer looking APIs. <code>@Accessors</code> lets you do this.
</p><p>
Some programmers like to use a prefix for their fields, i.e. they write <code>fPepper</code> instead of <code>pepper</code>.
We <em>strongly</em> discourage doing this, as you can't unit test the validity of your prefixes, and refactor scripts may turn fields
into local variables or method names. Furthermore, your tools (such as your editor) can take care of rendering the identifier in a
certain way if you want this information to be instantly visible. Nevertheless, you can list the prefixes that your project uses via
<code>@Accessors</code> as well.
</p><p>
<code>@Accessors</code> therefore has 3 options:<ul>
<li><code>fluent</code> - A boolean. If <em>true</em>, the getter for <code>pepper</code> is just <code>pepper()</code>, and the
setter is <code>pepper(T newValue)</code>. Furthermore, unless specified, <code>chain</code> defaults to <em>true</em>.<br />
Default: <em>false</em>.</li>
<li><code>chain</code> - A boolean. If <em>true</em>, generated setters return <code>this</code> instead of <code>void</code>.<br />
Default: <em>false</em>, unless <code>fluent=true</code>, then Default: <em>true</em>.</li>
<li><code>prefix</code> - A list of strings. If present, fields must be prefixed with any of these prefixes. Each field name is
compared to each prefix in the list in turn, and if a match is found, the prefix is stripped out to create the base name for
the field. It is legal to include an empty string in the list, which will always match. For characters which are letters, the
character following the prefix must not be a lowercase letter, i.e. <code>pepper</code> is not a match even to prefix <code>p</code>,
but <code>pEpper</code> would be (and would mean the base name of this field is <code>epper</code>).</li>
</p><p>
The <code>@Accessors</code> annotation is legal on types and fields; the annotation that applies is the one on the field if present,
otherwise the one on the class. When a <code>@Accessors</code> annotation on a field is present, any <code>@Accessors</code> annotation
also present on that field's type is ignored.
</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">
<h3>Small print</h3><div class="smallprint">
<p>
The nearest <code>@Accessors</code> annotation is also used for the various methods in lombok that look for getters, such as
<code>@EqualsAndHashCode</code>.
</p><p>
If a prefix list is provided and a field does not start with one of them, that field is skipped entirely by lombok, and
a warning will be generated.
</p>
</div>
</div>
<div class="footer">
<a href="index.html">Back to experimental features</a> | <span class="disabled">Previous feature</span> | <a href="ExtensionMethod.html">Next feature (@ExtensionMethod)</a><br />
<a href="../../credits.html" class="creditsLink">credits</a> | <span class="copyright">Copyright © 2009-2013 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>
|