How to use @EqualsAndHashCode With Include - Lombok

前端 未结 3 1368
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:36

    You should use it on the field, it's not something to be used on the class itself. You can check this by checking the definition of the annotation which defines the following targets (field and method, not a class)

    @Target({ElementType.FIELD, ElementType.METHOD})
    

    Here is an example of how to use it

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

提交回复
热议问题