aboutsummaryrefslogtreecommitdiff
path: root/src/core/lombok/EqualsAndHashCode.java
diff options
context:
space:
mode:
authorReinier Zwitserloot <r.zwitserloot@projectlombok.org>2020-10-03 23:56:41 +0200
committerReinier Zwitserloot <r.zwitserloot@projectlombok.org>2020-10-03 23:56:41 +0200
commit58545cec67ada261d13c454fce460ed55798cd72 (patch)
tree8c140dd3d788da876998c10b2d1f2bf9f3e1c91b /src/core/lombok/EqualsAndHashCode.java
parent14cce76805324dce66fcdfde333a63c677694d64 (diff)
parent4f763367f1092546350324f3040fa84cb0380409 (diff)
downloadlombok-58545cec67ada261d13c454fce460ed55798cd72.tar.gz
lombok-58545cec67ada261d13c454fce460ed55798cd72.tar.bz2
lombok-58545cec67ada261d13c454fce460ed55798cd72.zip
Merge remote-tracking branch 'origin/master'
# Conflicts: # src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java
Diffstat (limited to 'src/core/lombok/EqualsAndHashCode.java')
-rw-r--r--src/core/lombok/EqualsAndHashCode.java23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/core/lombok/EqualsAndHashCode.java b/src/core/lombok/EqualsAndHashCode.java
index 6805d214..279e6e3d 100644
--- a/src/core/lombok/EqualsAndHashCode.java
+++ b/src/core/lombok/EqualsAndHashCode.java
@@ -71,6 +71,14 @@ public @interface EqualsAndHashCode {
* @return If {@code true}, always use direct field access instead of calling the getter method.
*/
boolean doNotUseGetters() default false;
+
+ /**
+ * Determines how the result of the {@code hashCode} method will be cached.
+ * <strong>default: {@link CacheStrategy#NEVER}</strong>
+ *
+ * @return The {@code hashCode} cache strategy to be used.
+ */
+ CacheStrategy cacheStrategy() default CacheStrategy.NEVER;
/**
* Any annotations listed here are put on the generated parameter of {@code equals} and {@code canEqual}.
@@ -132,4 +140,19 @@ public @interface EqualsAndHashCode {
*/
int rank() default 0;
}
+
+ public enum CacheStrategy {
+ /**
+ * Never cache. Perform the calculation every time the method is called.
+ */
+ NEVER,
+ /**
+ * Cache the result of the first invocation of {@code hashCode} and use it for subsequent invocations.
+ * This can improve performance if all fields used for calculating the {@code hashCode} are immutable
+ * and thus every invocation of {@code hashCode} will always return the same value.
+ * <strong>Do not use this if there's <em>any</em> chance that different invocations of {@code hashCode}
+ * might return different values.</strong>
+ */
+ LAZY
+ }
}