How to compare objects by multiple fields

后端 未结 22 2589
暖寄归人
暖寄归人 2020-11-22 00:43

Assume you have some objects which have several fields they can be compared by:

public class Person {

    private String firstName;
    private String lastN         


        
22条回答
  •  误落风尘
    2020-11-22 01:16

    Its easy to do using Google's Guava library.

    e.g. Objects.equal(name, name2) && Objects.equal(age, age2) && ...

    More examples:

    • https://stackoverflow.com/a/5039178/1180621

提交回复
热议问题