Java中如何判斷兩個對象是否相等


參考:https://blog.csdn.net/u013063153/article/details/78808923

下面是自己開發過程中的實現

package com.***.***.entity
import lombok.Data;
import lombok.ToString;

@ToString(callSuper = true) @Data public class ****Scene implements Scene{ String method; String chunk; String size; int concurrent; /** *重寫了equals方法,兩個對象相等要么兩個對象的地址相同,要么兩個對象的內容相同 */ @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; ****Scene other = (****Scene) obj; if (concurrent != other.concurrent) return false; if (chunk == null) { if (other.chunk != null) { return false; } } else if (!chunk.equals(other.chunk)) return false; if (size == null) { if (other.size != null) { return false; } } else if (!size.equals(other.size)) return false; if (method == null) { if (other.method != null) { return false; } } else if (!method.equals(other.method)) return false; return true; } public String getString(){ return method+"_"+size+"_"+chunk+"_"; } }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM