override equals method to compare more than one field in java

后端 未结 6 549
予麋鹿
予麋鹿 2021-01-14 11:53

What is the best way to override equals method in java to compare more than one field? For example, I have 4 objects in the class, o1, o2, o3, o4 and I want compare all of t

6条回答
  •  伪装坚强ぢ
    2021-01-14 12:44

    A cheap way would be to do:

    Arrays.asList(o1, o2, o3, o4).equals(Arrays.asList(obj.o1, obj.o2, obj.o3, obj.o4));
    

提交回复
热议问题