aboutsummaryrefslogtreecommitdiff
path: root/website
diff options
context:
space:
mode:
Diffstat (limited to 'website')
-rw-r--r--website/features/Data.html44
-rw-r--r--website/features/EqualsAndHashCode.html88
-rw-r--r--website/features/GetterSetter.html2
-rw-r--r--website/features/ToString.html78
-rw-r--r--website/features/index.html9
5 files changed, 196 insertions, 25 deletions
diff --git a/website/features/Data.html b/website/features/Data.html
index b6f0cc85..ee81405a 100644
--- a/website/features/Data.html
+++ b/website/features/Data.html
@@ -11,31 +11,34 @@
<div class="meat">
<div class="header"><a href="../index.html">Project Lombok</a></div>
<h1>@Data</h1>
- <div class="byline">'struct' for java: Automatically generate <code>toString</code>, <code>hashCode</code>, <code>equals</code>, a constructor, and getters and setters
- from just the fields in your class.</div>
+ <div class="byline">All together now: A shortcut for <code>@ToString</code>, <code>@EqualsAndHashCode</code>,
+ <code>@Getter</code> on all fields, and <code>@Setter</code> on all non-final fields. You even
+ get a free constructor to initialize your final fields!</div>
<div class="overview">
<h3>Overview</h3>
<p>
- Any class definition may be annotated with <code>@Data</code> to let lombok generate all the boilerplate that is associated with simple POJOs
- (Plain Old Java Objects) and beans: getters for all fields, setters for all non-final fields, a useful <code>toString</code>, and implementations
- of <code>hashCode</code> and <code>equals</code> which consider any two objects of this type with the same values for each field as equal. A
- constructor is also generated containing 1 parameter for each final field, in the order the fields are defined. This constructor simply assigns
- each parameter to the appropriate field.
- </p>
- <p>
- To override the access level of any getter/setter for any field, annotate the field with a <code>@Setter</code> or <code>@Getter</code> annotation
- with the appropriate <code>AccessLevel</code> value. See the example below. For more information on how the getters/setters are generated,
- see the documentation for <a href="GetterSetter.html"><code>@Getter</code> and <code>@Setter</code></a>.
+ <code>@Data</code> is a convenient shortcut annotation that bundles the features of <a href="ToString.html"><code>@ToString</code></a>,
+ <a href="EqualsAndHashCode.html">@EqualsAndHashCode</code></a> and <a href="GetterSetter.html"><code>@Getter</code> / <code>@Setter</code></a>
+ together: In other words, <code>@Data</code> generates <em>all</em> the boilerplate that is normally associated with simple POJOs
+ (Plain Old Java Objects) and beans: getters for all fields, setters for all non-final fields, and appropriate <code>toString</code>, <code>equals</code>
+ and <code>hashCode</code> implementations that involve the fields of the class. In addition, <code>@Data</code> generates a constructor that
+ initialized all final fields.
+ </p><p>
+ <code>@Data</code> is like having implicit <code>@ToString</code> and <code>@EqualsAndHashCode</code> annotations on the class.
+ However, the parameters of <code>@ToString</code> and <code>@EqualsAndHashCode</code> (such as <code>callSuper</code>, <code>includeFieldNames</code> and
+ <code>exclude</code>) cannot be set with <code>@Data</code>. If you need to set non-default values for any of these parameters, just add those annotations
+ explicitly; <code>@Data</code> is smart enough to defer to those annotations.
+ </p><p>
+ All generated getters and setters will be <code>public</code>. To override the access level, annotate the field with an explicit <code>@Setter</code> and/or
+ <code>@Getter</code> annotation.
</p><p>
All fields marked as <code>transient</code> will not be considered for <code>hashCode</code> and <code>equals</code>. All static fields will be
skipped entirely (not considered for any of the generated methods, and no setter/getter will be made for them).
- The generated getter/setter method will be <code>public</code> unless you explicitly specify an <code>AccessLevel</code>, as shown in the example below.
- Legal access levels are <code>PUBLIC</code>, <code>PROTECTED</code>, <code>PACKAGE</code>, and <code>PRIVATE</code>.
</p><p>
- If any method that would normally be generated exists <em>in name</em> that method will not be generated, and no warning or error is emitted. For example,
- if you already have a method with signature <code>void hashCode(int a, int b, int c)</code>, no <code>int hashCode()</code> method will be generated,
- even though technically <code>int hashCode()</code> is an entirely different method. The same rule applies to the constructor, <code>toString</code>,
- <code>hashCode</code>, and all getters and setters.
+ If the class already contains a method with the same name as any method that would normally be generated, that method is not generated, and no warning or
+ error is emitted. For example, if you already have a method with signature <code>void hashCode(int a, int b, int c)</code>, no <code>int hashCode()</code>
+ method will be generated, even though technically <code>int hashCode()</code> is an entirely different method. The same rule applies to the constructor,
+ <code>toString</code>, <code>equals</code>, and all getters and setters.
</p><p>
<code>@Data</code> can handle generics parameters for fields just fine. In order to reduce the boilerplate when constructing objects for classes with
generics, you can use the <code>staticConstructor</code> parameter to generate a private constructor, as well as a static method that returns a new
@@ -61,9 +64,6 @@
Arrays are 'deep' compared/printed/hashCoded, which means that arrays that contain themselves will result in <code>StackOverflowError</code>s. However,
this behaviour is no different from e.g. <code>ArrayList</code>.
</p><p>
- You may safely presume that the hashCode implementation used will not change between versions of lombok, however this guarantee is not set in stone;
- if there's a significant performance improvement to be gained from using an alternate hash algorithm, that will be substituted in a future version.
- </p><p>
For a general idea of how lombok generated the <code>equals</code>, <code>hashCode</code>, and <code>toString</code> methods, check the example after.
</p><p>
For the purposes of equality, 2 <code>NaN</code> (not a number) values for floats and doubles are considered equal, eventhough 'NaN == NaN' would
@@ -73,7 +73,7 @@
</div>
</div>
<div class="footer">
- <a href="index.html">Back to features</a> | <a href="GetterSetter.html">Previous feature (@Getter / @Setter)</a> | <a href="Cleanup.html">Next feature (@Cleanup)</a><br />
+ <a href="index.html">Back to features</a> | <a href="EqualsAndHashCode.html">Previous feature (@EqualsAndHashCode)</a> | <a href="Cleanup.html">Next feature (@Cleanup)</a><br />
<a href="../credits.html" class="creditsLink">credits</a> | <span class="copyright">Copyright &copy; 2009 Reinier Zwitserloot and Roel Spilker, licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT licence</a>.</span>
</div>
<div style="clear: both;"></div>
diff --git a/website/features/EqualsAndHashCode.html b/website/features/EqualsAndHashCode.html
new file mode 100644
index 00000000..3e19814c
--- /dev/null
+++ b/website/features/EqualsAndHashCode.html
@@ -0,0 +1,88 @@
+<!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>@Data</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>@EqualsAndHashCode</h1>
+ <div class="byline">Equality made easy: Generates <code>hashCode</code> and <code>equals</code> implementations from the fields of your object.</div>
+ <div class="overview">
+ <h3>Overview</h3>
+ <p>
+ Any class definition may be annotated with <code>@EqualsAndHashCode</code> to let lombok generate implementations of the
+ <code>equals(Object other)</code> and <code>hashCode()</code> methods. By default, it'll use all non-static, non-transient
+ fields, but you can exclude more fields by naming them in the optional <code>exclude</code> parameter to the annotation.
+ </p><p>
+ By setting <code>callSuper</code> to <em>true</em>, you can include the <code>equals</code> and <code>hashCode</code> methods of your superclass in the generated methods.
+ For <code>hashCode</code>, the result of <code>super.hashCode()</code> is included in the hash algorithm, and for <code>equals</code>, the generated method will return
+ false if the super implementation thinks it is not equal to the passed in object. Be aware that not all <code>equals</code> implementations handle this situation properly.
+ However, lombok-generated <code>equals</code> implementations <strong>do</strong> handle this situation properly, so you can safely call your superclass equals if it, too,
+ has a lombok-generated <code>equals</code> method.<br />
+ </p><p>
+ Setting <code>callSuper</code> to <em>true</em> when you don't extend anything (you extend <code>java.lang.Object</code>) is a compile-time error, because it would turn
+ the generated <code>equals()</code> and <code>hashCode()</code> implementations into having the same behaviour as simply inheriting these methods from <code>java.lang.Object</code>:
+ only the same object will be equal to each other and will have the same hashCode. Obviously, inheriting <code>java.lang.Object</code> is the right strategy if you want this behaviour.
+ Not setting <code>callSuper</code> to <em>true</em> when you extend another class generates a warning, because unless the superclass has no (equality-important) fields, lombok
+ cannot generate an implementation for you that takes into account the fields declared by your superclasses. You'll need to write your own implementations, or rely on the
+ <code>callSuper</code> chaining facility.
+ </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>
+ Arrays are 'deep' compared/hashCoded, which means that arrays that contain themselves will result in <code>StackOverflowError</code>s. However,
+ this behaviour is no different from e.g. <code>ArrayList</code>.
+ </p><p>
+ You may safely presume that the hashCode implementation used will not change between versions of lombok, however this guarantee is not set in stone;
+ if there's a significant performance improvement to be gained from using an alternate hash algorithm, that will be substituted in a future version.
+ </p><p>
+ For the purposes of equality, 2 <code>NaN</code> (not a number) values for floats and doubles are considered equal, eventhough 'NaN == NaN' would
+ return false. This is analogous to <code>java.lang.Double</code>'s equals method, and is in fact required to ensure that comparing an object
+ to an exact copy of itself returns <code>true</code> for equality.
+ </p><p>
+ If there is <em>any</em> method named either <code>hashCode</code> or <code>equals</code>, regardless of parameters or return type,
+ that method will not be generated, and a warning is emitted instead. <code>hashCode</code> and <code>equals</code> need to be in sync with
+ each other, which lombok cannot guarantee if it is only generating one of the two methods, hence you always get a warning if one <em>or</em> both
+ of the methods already exist.
+ </p><p>
+ Attempting to exclude fields that don't exist or would have been excluded anyway (because they are static) results in warnings on the named fields.
+ You therefore don't have to worry about typos.
+ </p>
+ </div>
+ </div>
+ <div class="footer">
+ <a href="index.html">Back to features</a> | <a href="ToString.html">Previous feature (@ToString)</a> | <a href="Data.html">Next feature (@Data)</a><br />
+ <a href="../credits.html" class="creditsLink">credits</a> | <span class="copyright">Copyright &copy; 2009 Reinier Zwitserloot and Roel Spilker, licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT licence</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>
diff --git a/website/features/GetterSetter.html b/website/features/GetterSetter.html
index b9844aad..8b42146f 100644
--- a/website/features/GetterSetter.html
+++ b/website/features/GetterSetter.html
@@ -52,7 +52,7 @@
</div>
</div>
<div class="footer">
- <a href="index.html">Back to features</a> | <span class="disabled">Previous feature</span> | <a href="Data.html">Next feature (@Data)</a><br />
+ <a href="index.html">Back to features</a> | <span class="disabled">Previous feature</span> | <a href="ToString.html">Next feature (@ToString)</a><br />
<a href="../credits.html" class="creditsLink">credits</a> | <span class="copyright">Copyright &copy; 2009 Reinier Zwitserloot and Roel Spilker, licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT licence</a>.</span>
</div>
<div style="clear: both;"></div>
diff --git a/website/features/ToString.html b/website/features/ToString.html
new file mode 100644
index 00000000..e970d88c
--- /dev/null
+++ b/website/features/ToString.html
@@ -0,0 +1,78 @@
+<!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>@Data</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>@ToString</h1>
+ <div class="byline">No need to start a debugger to see your fields: Just let lombok generate a <code>toString</code> for you!</div>
+ <div class="overview">
+ <h3>Overview</h3>
+ <p>
+ Any class definition may be annotated with <code>@ToString</code> to let lombok generate an implementation of the
+ <code>toString()</code> method. By default, it'll print your class name, along with each field, in order, separated by commas.
+ </p><p>
+ By setting the <code>includeFieldNames</code> parameter to <em>true</em> you can add some clarity (but also quite some length) to
+ the output of the <code>toString()</code> method.
+ </p><p>
+ All non-static fields will be printed. If you want to skip some fields, you can name them in the <code>exclude</code> parameter; each named
+ field will not be printed at all.
+ </p><p>
+ By setting <code>callSuper</code> to <em>true</em>, you can include the output of the superclass implementation of <code>toString</code> to the
+ output. Be aware that the default implementation of <code>toString()</code> in <code>java.lang.Object</code> is pretty much meaningless, so you
+ probably don't want to do this unless you are extending another class.
+ </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>
+ If there is <em>any</em> method named <code>toString</code> regardless of parameters or return type, no method will be generated, and instead
+ a warning is emitted explaining that your <code>@ToString</code> annotation is doing nothing.
+ </p><p>
+ Arrays are printed via <code>Arrays.deepToString</code>, which means that arrays that contain themselves will result in <code>StackOverflowError</code>s. However,
+ this behaviour is no different from e.g. <code>ArrayList</code>.
+ </p><p>
+ Attempting to exclude fields that don't exist or would have been excluded anyway (because they are static) results in warnings on the named fields.
+ You therefore don't have to worry about typos.
+ </p><p>
+ We don't promise to keep the output of the generated <code>toString()</code> methods the same between lombok versions. You should never design your API so that
+ other code is forced to parse your <code>toString()</code> output anyway!
+ </p>
+ </div>
+ </div>
+ <div class="footer">
+ <a href="index.html">Back to features</a> | <a href="GetterSetter.html">Previous feature (@Getter / @Setter)</a> | <a href="EqualsAndHashCode.html">Next feature (@EqualsAndHashCode)</a><br />
+ <a href="../credits.html" class="creditsLink">credits</a> | <span class="copyright">Copyright &copy; 2009 Reinier Zwitserloot and Roel Spilker, licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT licence</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>
diff --git a/website/features/index.html b/website/features/index.html
index 921e1d94..5a5387b9 100644
--- a/website/features/index.html
+++ b/website/features/index.html
@@ -15,9 +15,14 @@
<dl>
<dt><a href="GetterSetter.html"><code>@Getter</code> / <code>@Setter</code></a></dt>
<dd>Never write <code>public int getFoo() {return foo;}</code> again.</dd>
+ <dt><a href="ToString.html"><code>@ToString</code></a></dt>
+ <dd>No need to start a debugger to see your fields: Just let lombok generate a <code>toString</code> for you!</dd>
+ <dt><a href="EqualsAndHashCode.html"><code>@EqualsAndHashCode</code></a></dt>
+ <dd>Equality made easy: Generates <code>hashCode</code> and <code>equals</code> implementations from the fields of your object.</dd>
<dt><a href="Data.html"><code>@Data</code></a></dt>
- <dd>'struct' for java: Automatically generate <code>toString</code>, <code>hashCode</code>, <code>equals</code>, a constructor, and getters and setters
- from just the fields in your class.</dd>
+ <dd>All together now: A shortcut for <code>@ToString</code>, <code>@EqualsAndHashCode</code>,
+ <code>@Getter</code> on all fields, and <code>@Setter</code> on all non-final fields. You even
+ get a free constructor to initialize your final fields!</dd>
<dt><a href="Cleanup.html"><code>@Cleanup</code></a></dt>
<dd>Automatic resource management: Call your <code>close()</code> methods safely with no hassle.</dd>
<dt><a href="Synchronized.html"><code>@Synchronized</code></a></dt>