`
Roader123
  • 浏览: 92330 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

equals and hashcode

 
阅读更多
一般重写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 = 37*result + keyfield;
result = 37*result + keyfield2;
return result;
}
分享到:
评论

相关推荐

    JDBC_sorting_Comparing_

    Java sorting objects with equals and hashcode override

    java 开发规范

    Object Model Violation: Just one of equals() and hashCode() Defined ABSTRACT This class overrides only one of equals() and hashCode().

    Generatable:可生成-Intellij IDEA插件

    可产生的可生成-Intellij IDEA插件插件向“生成”菜单添加了一些操作: Generate inner Builder classGenerate All: getters, equals and hashCode, toString, Constructor, Builder也可以看看: FuGen - You can ...

    Java教程补充材料

    10 The Methods in the Object Class (finalize, hashcode, clone, getClass, equals) 11 Hiding Data Fields and Static Methods 12 Initialization Blocks 13 Extended Discussions on Overriding Methods 14...

    Effective Java 3rd edition(Effective Java第三版英文原版)附第二版

    Item 11: Always override hashCode when you override equals Item 12: Always override toString Item 13: Override clone judiciously Item 14: Consider implementing Comparable 4 Classes and Interfaces Item...

    Hibernate Reference Documentation3.1

    4.3. Implementing equals() and hashCode() 4.4. Dynamic models 4.5. Tuplizers 5. Basic O/R Mapping 5.1. Mapping declaration 5.1.1. Doctype 5.1.2. hibernate-mapping 5.1.3. class 5.1.4. id 5.1.4.1. ...

    生成Eclipce的Java插件Jenerate.zip

    hashCode() and equals() toString() compareTo() 标签:Jenerate 分享 window._bd_share_config = { ...

    sesvc.exe 阿萨德

    * for keySet() and values(). */ transient Set,V>> entrySet; /** * The number of key-value mappings contained in this map. */ transient int size; 和 1.7 大体上都差不多,还是有几个重要的区别: ...

    java8源码-JavaInterview-5:java中高级面试指南

    hashcode相等两个类一定相等吗? equals 呢 相反呢? () 线程池用过么?都有哪些参数? 底层如何实现? () () () () () synchized和lock什么区别? 底层细节 () () () threadLocal是什么?底层如何实现?写一个例子 ...

    Hibernate3的帮助文档

    5.3. 实现equals()和hashCode() 5.4. 动态模型(Dynamic models) 6. 对象/关系数据库映射基础(Basic O/R Mapping) 6.1. 映射定义(Mapping declaration) 6.1.1. Doctype 6.1.2. hibernate-mapping 6.1.3. class...

    Hibernate参考文档

    4.3. 实现equals()和hashCode() 4.4. 动态模型(Dynamic models) 4.5. 元组片断映射(Tuplizers) 5. 对象/关系数据库映射基础(Basic O/R Mapping) 5.1. 映射定义(Mapping declaration) 5.1.1. Doctype 5.1.1.1. ...

    Hibernate 中文 html 帮助文档

    4.3. 实现equals()和hashCode() 4.4. 动态模型(Dynamic models) 4.5. 元组片断映射(Tuplizers) 5. 对象/关系数据库映射基础(Basic O/R Mapping) 5.1. 映射定义(Mapping declaration) 5.1.1. Doctype 5.1.1.1. ...

    hibernate 教程

    实现equals()和hashCode() 4.4. 持久化生命周期(Lifecycle)中的回调(Callbacks) 4.5. 合法性检查(Validatable)回调 4.6. XDoclet标记示例 5. O/R Mapping基础 5.1. 映射声明(Mapping ...

    hibernate

    实现equals()和hashCode() 4.4. 持久化生命周期(Lifecycle)中的回调(Callbacks) 4.5. 合法性检查(Validatable)回调 4.6. XDoclet标记示例 5. O/R Mapping基础 5.1. 映射声明(Mapping ...

    最全Hibernate 参考文档

    4.3. 实现equals()和hashCode() 4.4. 动态模型(Dynamic models) 5. 对象/关系数据库映射基础(Basic O/R Mapping) 5.1. 映射定义(Mapping declaration) 5.1.1. Doctype 5.1.2. hibernate-mapping 5.1.3. class ...

    hibernate 框架详解

    实现equals()和hashCode() 5.4. 动态模型(Dynamic models) 6. 对象/关系数据库映射基础(Basic O/R Mapping) 6.1. 映射定义(Mapping declaration) 6.1.1. Doctype 6.1.2. hibernate-mapping 6.1.3. class ...

    Hibernate3+中文参考文档

    4.3. 实现equals()和hashCode() 4.4. 动态模型(Dynamic models) 5. 对象/关系数据库映射基础(Basic O/R Mapping) 5.1. 映射定义(Mapping declaration) 5.1.1. Doctype 5.1.2. hibernate-mapping 5.1.3. class ...

    Hibernate注释大全收藏

    //appropriate equals() and hashCode() implementation } @Embeddable public class FootballerPk implements Serializable { //same name and type as in Footballer public String getFirstname() { return ...

    hibernate3.04中文文档.chm

    5.3. 实现equals()和hashCode() 5.4. 动态模型(Dynamic models) 6. 对象/关系数据库映射基础(Basic O/R Mapping) 6.1. 映射定义(Mapping declaration) 6.1.1. Doctype 6.1.2. hibernate-mapping 6.1.3. ...

    Hibernate教程

    5.3. 实现equals()和hashCode() 5.4. 动态模型(Dynamic models) 6. 对象/关系数据库映射基础(Basic O/R Mapping) 6.1. 映射定义(Mapping declaration) 6.1.1. Doctype 6.1.2. hibernate-mapping 6.1.3. class...

Global site tag (gtag.js) - Google Analytics