@Target(value=TYPE) @Retention(value=SOURCE) public @interface EqualsAndHashCode
equals
and hashCode
methods inherited by all objects, based on relevant fields.
Complete documentation is found at the project lombok features page for @EqualsAndHashCode.
Modifier and Type | Optional Element and Description |
---|---|
EqualsAndHashCode.CacheStrategy |
cacheStrategy
Determines how the result of the
hashCode method will be cached. |
boolean |
callSuper
Call on the superclass's implementations of
equals and hashCode before calculating for the fields in this class. |
boolean |
doNotUseGetters
Normally, if getters are available, those are called.
|
String[] |
exclude
Any fields listed here will not be taken into account in the generated
equals and hashCode implementations. |
String[] |
of
If present, explicitly lists the fields that are to be used for identity.
|
boolean |
onlyExplicitlyIncluded
Only include fields and methods explicitly marked with
@EqualsAndHashCode.Include . |
EqualsAndHashCode.AnyAnnotation[] |
onParam
Any annotations listed here are put on the generated parameter of
equals and canEqual . |
public abstract String[] exclude
equals
and hashCode
implementations.
Mutually exclusive with of()
.
Will soon be marked @Deprecated
; use the @EqualsAndHashCode.Exclude
annotation instead.
public abstract String[] of
Mutually exclusive with exclude()
.
Will soon be marked @Deprecated
; use the @EqualsAndHashCode.Include
annotation together with @EqualsAndHashCode(onlyExplicitlyIncluded = true)
.
public abstract boolean callSuper
equals
and hashCode
before calculating for the fields in this class.
default: falseequals
implementation as part of the generated equals algorithm.public abstract boolean doNotUseGetters
true
.
default: falsetrue
, always use direct field access instead of calling the getter method.public abstract EqualsAndHashCode.CacheStrategy cacheStrategy
hashCode
method will be cached.
default: EqualsAndHashCode.CacheStrategy.NEVER
hashCode
cache strategy to be used.public abstract EqualsAndHashCode.AnyAnnotation[] onParam
equals
and canEqual
.
This is useful to add for example a Nullable
annotation.@EqualsAndHashCode(onParam=@__({@AnnotationsGoHere}))
@EqualsAndHashCode(onParam_={@AnnotationsGohere})
// note the underscore after onParam
.equals()
method.public abstract boolean onlyExplicitlyIncluded
@EqualsAndHashCode.Include
.
Normally, all (non-static, non-transient) fields are included by default.true
, don't include non-static non-transient fields automatically (default: false
).Copyright © 2024. All rights reserved.