diff options
author | Reinier Zwitserloot <reinier@tipit.to> | 2009-09-03 01:44:59 +0200 |
---|---|---|
committer | Reinier Zwitserloot <reinier@tipit.to> | 2009-09-03 01:44:59 +0200 |
commit | f1124aad02569c983cb8979445245141bf029a88 (patch) | |
tree | 80d25bb1dddcfce46931f298b6f70ebdbd2e3e13 /src/lombok/EqualsAndHashCode.java | |
parent | 6b7919166e9a550d7d2b1f7156c794e76905fcab (diff) | |
download | lombok-f1124aad02569c983cb8979445245141bf029a88.tar.gz lombok-f1124aad02569c983cb8979445245141bf029a88.tar.bz2 lombok-f1124aad02569c983cb8979445245141bf029a88.zip |
Addressed issue #32: The @EqualsAndHashCode and @ToString annotations now support explicitly listing the fields to use, via the new 'of' parameter.
We've also added any fields that start with $ to the default excludes list. Lombok itself can generate these fields ($lock of @Synchronized, for example), and in general they probably should count as effectively not part of the class.
Diffstat (limited to 'src/lombok/EqualsAndHashCode.java')
-rw-r--r-- | src/lombok/EqualsAndHashCode.java | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/lombok/EqualsAndHashCode.java b/src/lombok/EqualsAndHashCode.java index ac2b95a1..597a6933 100644 --- a/src/lombok/EqualsAndHashCode.java +++ b/src/lombok/EqualsAndHashCode.java @@ -35,8 +35,9 @@ import java.lang.annotation.Target; * a method; any method named <code>hashCode</code> will make <code>@EqualsAndHashCode</code> not generate that method, * for example. * <p> - * All fields that are non-static and non-transient are used in the equality check and hashCode generation. You can exclude - * more fields by specifying them in the <code>exclude</code> parameter. + * By default, all fields that are non-static and non-transient are used in the equality check and hashCode generation. + * You can exclude more fields by specifying them in the <code>exclude</code> parameter. You can also explicitly specify + * the fields that are to be used by specifying them in the <code>of</code> parameter. * <p> * Normally, auto-generating <code>hashCode</code> and <code>equals</code> implementations in a subclass is a bad idea, as * the superclass also defines fields, for which equality checks/hashcodes won't be auto-generated. Therefore, a warning @@ -58,10 +59,19 @@ public @interface EqualsAndHashCode { /** * Any fields listed here will not be taken into account in the generated * <code>equals</code> and <code>hashCode</code> implementations. + * Mutually exclusive with {@link #of()}. */ String[] exclude() default {}; /** + * If present, explicitly lists the fields that are to be printed. + * Normally, all non-static, non-transient fields are printed. + * <p> + * Mutually exclusive with {@link #exclude()}. + */ + String[] of() default {}; + + /** * Call on the superclass's implementations of <code>equals</code> and <code>hashCode</code> before calculating * for the fields in this class. * <strong>default: false</strong> |