diff options
Diffstat (limited to 'website/features/experimental/Wither.html')
-rw-r--r-- | website/features/experimental/Wither.html | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/website/features/experimental/Wither.html b/website/features/experimental/Wither.html new file mode 100644 index 00000000..34d6d0d9 --- /dev/null +++ b/website/features/experimental/Wither.html @@ -0,0 +1,100 @@ +<!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 - @ExtensionMethod</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>@Wither</h1> + <div class="byline">Immutable 'setters' - methods that create a clone but with one changed field.</div> + <div class="since"> + <h3>Since</h3> + <p> + @Wither was introduced as experimental feature in lombok v0.11.4. + </p> + </div> + <div class="experimental"> + <h3>Experimental</h3> + <p> + Experimental because: + <ul> + <li>Still not sure that <code>@Wither</code> is an appropriate name for this feature.</li> + <li>Should there be an option to supply a way of cloning the input somehow?</li> + <li>Should the way that the clone is created by configurable?</li> + <li>Should we replace @Wither entirely with a builder class?</li> + </ul> + Current status: <em>neutral</em> - More feedback requires on the items in the above list before promotion to the main package is warranted. + </div> + <div class="overview"> + <h3>Overview</h3> + <p> + The next best alternative to a setter for an immutable property is to construct a clone of the object, but with a new value for this one field. + A method to generate this clone is precisely what <code>@Wither</code> generates: a <code>withFieldName(newValue)</code> method which produces a clone + except for the new value for the associated field. + </p><p> + For example, if you create <code>public class Point { private final int x, y; }</code>, setters make no sense because the fields + are final. <code>@Wither</code> can generate a <code>withX(int newXValue)</code> method for you which will return a new point with the supplied + value for <code>x</code> and the same value for <code>y</code>. + </p><p> + Like <a href="../GetterSetter.html"><code>@Setter</code></a>, you can specify an access level in case you want the generated wither to be something other than <code>public</code>:<br /> + <code>@Wither(level = AccessLevel.PROTECTED)</code>. Also like <a href="../GetterSetter.html"><code>@Setter</code></a>, you can also put a <code>@Wither</code> annotation on a type, which means + a 'wither' is generated for each field (even non-final fields). + </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> + Withers cannot be generated for static fields because that makes no sense. + </p><p> + When applying <code>@Wither</code> to a type, static fields and fields whose name start with a $ are skipped. + </p><p> + For generating the method names, the first character of the field, if it is a lowercase character, is title-cased, otherwise, it is left unmodified. + Then, <code>with</code> is prefixed. + </p><p> + No method is generated if any method already exists with the same name (case insensitive) and same parameter count. For example, <code>withX(int x)</code> + will not be generated if there's already a method <code>withX(String... x)</code> even though it is technically possible to make the method. This caveat + exists to prevent confusion. If the generation of a method is skipped for this reason, a warning is emitted instead. Varargs count as 0 to N parameters. + </p><p> + For <code>boolean</code> fields that start with <code>is</code> immediately followed by a title-case letter, nothing is prefixed to generate the wither name. + </p><p> + Any annotations named <code>@NonNull</code> (case insensitive) on the field are interpreted as: This field must not ever hold + <em>null</em>. Therefore, these annotations result in an explicit null check in the generated wither. Also, these + annotations (as well as any annotation named <code>@Nullable</code> or <code>@CheckForNull</code>) are copied to wither parameter. + </p> + </div> + </div> + <div class="footer"> + <a href="index.html">Back to experimental features</a> | <a href="FieldDefaults.html">Previous feature (@FieldDefaults)</a> | <a href="Value.html">Next feature (@Value)</a><br /> + <a href="../../credits.html" class="creditsLink">credits</a> | <span class="copyright">Copyright © 2009-2012 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> |