Overriding the java equals() method - not working?

后端 未结 8 1343
花落未央
花落未央 2020-11-22 02:33

I ran into an interesting (and very frustrating) issue with the equals() method today which caused what I thought to be a well tested class to crash and cause a

8条回答
  •  孤城傲影
    2020-11-22 03:03

    recordId is property of the object

    @Override
        public boolean equals(Object obj) {
            if (this == obj)
                return true;
            if (obj == null)
                return false;
            if (getClass() != obj.getClass())
                return false;
            Nai_record other = (Nai_record) obj;
            if (recordId == null) {
                if (other.recordId != null)
                    return false;
            } else if (!recordId.equals(other.recordId))
                return false;
            return true;
        }
    

提交回复
热议问题