How to use @EqualsAndHashCode With Include - Lombok

前端 未结 3 1356
Happy的楠姐
Happy的楠姐 2021-02-19 02:42

How to use @EqualsAndHashCode With Include, Lombok library for Java.

@EqualsAndHashCode.Include( )

How to make Equal

3条回答
  •  生来不讨喜
    2021-02-19 03:35

    From Lombok, Just add the @EqualsAndHashCode.Include or @EqualsAndHashCode.Exclude on required fields

    Any class definition may be annotated with @EqualsAndHashCode to let lombok generate implementations of the equals(Object other) and hashCode() methods. By default, it'll use all non-static, non-transient fields, but you can modify which fields are used (and even specify that the output of various methods is to be used) by marking type members with @EqualsAndHashCode.Include or @EqualsAndHashCode.Exclude. Alternatively, you can specify exactly which fields or methods you wish to be used by marking them with @EqualsAndHashCode.Include and using @EqualsAndHashCode(onlyExplicitlyIncluded = true).

    @EqualsAndHashCode
    @Table(name = "USER")
    public class User
      {
    
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Column(name = "IDENTITY_USER")
      @EqualsAndHashCode.Include
      private Long identity;
     }
    

提交回复
热议问题