Package lombok

Annotation Type EqualsAndHashCode


@Target(TYPE) @Retention(SOURCE) public @interface EqualsAndHashCode
Generates implementations for the equals and hashCode methods inherited by all objects, based on relevant fields.

Complete documentation is found at the project lombok features page for @EqualsAndHashCode.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static @interface 
    Deprecated.
    Don't use this annotation, ever - Read the documentation.
    static enum 
     
    static @interface 
    If present, do not include this field in the generated equals and hashCode methods.
    static @interface 
    Configure the behaviour of how this member is treated in the equals and hashCode implementation; if on a method, include the method's return value as part of calculating hashCode/equality.
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    Determines how the result of the hashCode method will be cached.
    boolean
    Call on the superclass's implementations of equals and hashCode before calculating for the fields in this class.
    boolean
    Normally, if getters are available, those are called.
    Any fields listed here will not be taken into account in the generated equals and hashCode implementations.
    If present, explicitly lists the fields that are to be used for identity.
    boolean
    Only include fields and methods explicitly marked with @EqualsAndHashCode.Include.
    Any annotations listed here are put on the generated parameter of equals and canEqual.
  • Element Details

    • exclude

      String[] exclude
      Any fields listed here will not be taken into account in the generated equals and hashCode implementations. Mutually exclusive with of().

      Will soon be marked @Deprecated; use the @EqualsAndHashCode.Exclude annotation instead.

      Returns:
      A list of fields to exclude.
      Default:
      {}
    • of

      String[] of
      If present, explicitly lists the fields that are to be used for identity. Normally, all non-static, non-transient fields are used for identity.

      Mutually exclusive with exclude().

      Will soon be marked @Deprecated; use the @EqualsAndHashCode.Include annotation together with @EqualsAndHashCode(onlyExplicitlyIncluded = true).

      Returns:
      A list of fields to use (default: all of them).
      Default:
      {}
    • callSuper

      boolean callSuper
      Call on the superclass's implementations of equals and hashCode before calculating for the fields in this class. default: false
      Returns:
      Whether to call the superclass's equals implementation as part of the generated equals algorithm.
      Default:
      false
    • doNotUseGetters

      boolean doNotUseGetters
      Normally, if getters are available, those are called. To suppress this and let the generated code use the fields directly, set this to true. default: false
      Returns:
      If true, always use direct field access instead of calling the getter method.
      Default:
      false
    • cacheStrategy

      Determines how the result of the hashCode method will be cached. default: EqualsAndHashCode.CacheStrategy.NEVER
      Returns:
      The hashCode cache strategy to be used.
      Default:
      NEVER
    • onParam

      Any annotations listed here are put on the generated parameter of equals and canEqual. This is useful to add for example a Nullable annotation.
      The syntax for this feature depends on JDK version (nothing we can do about that; it's to work around javac bugs).
      up to JDK7:
      @EqualsAndHashCode(onParam=@__({@AnnotationsGoHere}))
      from JDK8:
      @EqualsAndHashCode(onParam_={@AnnotationsGohere}) // note the underscore after onParam.
      Returns:
      List of annotations to apply to the generated parameter in the equals() method.
      Default:
      {}
    • onlyExplicitlyIncluded

      boolean onlyExplicitlyIncluded
      Only include fields and methods explicitly marked with @EqualsAndHashCode.Include. Normally, all (non-static, non-transient) fields are included by default.
      Returns:
      If true, don't include non-static non-transient fields automatically (default: false).
      Default:
      false