From 3019e73f965c40f0b72ad2b04553f3c9a694b3d2 Mon Sep 17 00:00:00 2001 From: Andre Brait Date: Thu, 9 Jul 2020 12:50:38 +0200 Subject: Attempt to implement cacheHashCode --- src/core/lombok/EqualsAndHashCode.java | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/core/lombok/EqualsAndHashCode.java') diff --git a/src/core/lombok/EqualsAndHashCode.java b/src/core/lombok/EqualsAndHashCode.java index 6805d214..d73afe13 100644 --- a/src/core/lombok/EqualsAndHashCode.java +++ b/src/core/lombok/EqualsAndHashCode.java @@ -71,6 +71,17 @@ public @interface EqualsAndHashCode { * @return If {@code true}, always use direct field access instead of calling the getter method. */ boolean doNotUseGetters() default false; + + /** + * Enables caching the result of {@code hashCode}. + * This is useful to prevent running expensive calculations of {@code hashCode} multiple times for fully immutable objects, where it would always return the same result. + * It is similar to what {@link java.lang.String#hashCode} does. + * This should only be used for fully immutable classes (classes with all-immutable fields). + * default: false + * + * @return If {@code true}, cache the result of {@code hashCode} to avoid recalculating it in future invocations. + */ + boolean cacheHashCode() default false; /** * Any annotations listed here are put on the generated parameter of {@code equals} and {@code canEqual}. -- cgit