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
|
<!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>@Delegate</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>@Delegate</h1>
<div class="byline">Don't lose your composition.</div>
<div class="overview">
<h3>Overview</h3>
<p>
<em> NEW IN Lombok 0.10: </em> Any field can be annotated with <code>@Delegate</code> to let lombok generate delegate methods that forward the call
to this field.
</p>
<p>
Lombok delegates all <code>public</code> methods of the field's type, as well as those of its supertype except for all methods declared
in <code>java.lang.Object</code>.
</p>
<p>
You can pass any number of classes into the <code>@Delegate</code> annotation's <code>types</code> parameter.
If you do that, then lombok will delegate all <code>public</code> methods in those types (and their supertypes, except
<code>java.lang.Object</code>) instead of looking at the field's type.
</p>
<p>
All public non-Object methods that are part of the field's type (or, if you used <code>types</code> parameter, the methods of those types) are
copied, whether or not you also wrote implementations for those methods. That would thus result in duplicate method errors. You can avoid these
by using the <code>@Delegate(excludes=SomeType.class)</code> parameter to exclude all public methods in the excluded type(s), and their supertypes.
</p>
<p>
To have very precise control over what is delegated and what isn't, write private inner interfaces with method signatures, then specify these
private inner interfaces as types in <code>@Delegate(types=PrivateInnerInterfaceWithIncludesList.class, excludes=SameForExcludes.class)</code>.
</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>
When passing classes to the annotation's <code>types</code> or <code>excludes</code> parameter, you cannot include generics.
This is a limitation of java. Use private inner interfaces or classes that extend the intended type including the
generics parameter to work around this problem.
</p>
<p>
When passing classes to the annotation, these classes do not need to be supertypes of the field. See the example.
</p>
<div>
</div>
<div class="footer">
<a href="index.html">Back to features</a> | <a href="val.html">Previous feature (val)</a> | <span class="disabled">Next feature</span><br />
<a href="../credits.html" class="creditsLink">credits</a> | <span class="copyright">Copyright © 2010-2011 Reinier Zwitserloot, Roel Spilker and Robbert Jan Grootjans, 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>
|