Object comparison for equality : JAVA

前端 未结 4 1103
野性不改
野性不改 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:43

    With the default implementation of Object.equals, two objects of different classes will never be the same.

    If you want that behavior, you will need to override .equals in your classes (and .hashcode as well, look at the javadoc).

    (Or make a comparator and pass it to your collections).

提交回复
热议问题