ITeye博客

equals and hashcode

Roader123 · 2011-09-10 18:30 · JAVA SE · 编程语言 · Markdown

一般重写equals, 需要重写hashcode。for hash Collection usage

public boolean equals(Object o){ if(o==this) return true; if(!(o instanceof CatchFinally)) return false; CatchFinally cf = (CatchFinally)o; return cf.keyfield == this.keyfield&&this.keyfield2.equals(cf.keyfield2); }

public int hashCode(){ int result =17; result = 37result + keyfield; result = 37result + keyfield2; return result; }

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。