Object comparison for equality : JAVA

前端 未结 4 1101
野性不改
野性不改 2020-12-21 14:20
public ClassA
{
private String firstId;
private String secondId;

public void setFirstId(String firstId) {
           this.firstId = firstId;
   }


   public String         


        
4条回答
  •  悲&欢浪女
    2020-12-21 14:52

    Eventhough content is same they are different objects which doesn't satifsy equal condition. You may need to do explicit a.getfirstId().equals(b.getfirsId()) and a.getscondID().equals(b.getSecondId()) by iterating.

    The other possibility may be overriding equals and hashcode methods in both POJO classes. Refer this link for equals/hashcode contract.

提交回复
热议问题