diff options
author | Andre Brait <andrebrait@gmail.com> | 2020-07-09 12:50:38 +0200 |
---|---|---|
committer | Roel Spilker <r.spilker@gmail.com> | 2020-09-24 22:25:15 +0200 |
commit | 3019e73f965c40f0b72ad2b04553f3c9a694b3d2 (patch) | |
tree | 6810dd773906e5e377514f602043217d74154927 /src/core/lombok/EqualsAndHashCode.java | |
parent | f397c2b4825828b5ad8a29ad1bee934a23199527 (diff) | |
download | lombok-3019e73f965c40f0b72ad2b04553f3c9a694b3d2.tar.gz lombok-3019e73f965c40f0b72ad2b04553f3c9a694b3d2.tar.bz2 lombok-3019e73f965c40f0b72ad2b04553f3c9a694b3d2.zip |
Attempt to implement cacheHashCode
Diffstat (limited to 'src/core/lombok/EqualsAndHashCode.java')
-rw-r--r-- | src/core/lombok/EqualsAndHashCode.java | 11 |
1 files changed, 11 insertions, 0 deletions
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). + * <strong>default: false</strong> + * + * @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}. |