zoukankan      html  css  js  c++  java
  • Effective Java 英文 第二版 读书笔记 Item 8:Obey the general contract when overriding equals

    title:重载equals方法要遵循的一般约定

    Each instance of the class is inherently unique 实例存在主键

    You don't care whether the class provides a "logical equality" test.

    so the equals implementation inherited form Object is adequate.

    使用场景

    when a class has a notion of logical equality that differs form mere object identity,

    and a superclass has not already overridden equals to implement the desired behavior

    基本原则

    use the == operator to check if the argument is a reference to this object

    use the instanceof operator to check if the argument has the corrcet type

    cast the argument to correct type.

    for each "significant" field in the class,check if that field of the argument matched the corresponding field of this object.

    Always override hashCode when you override equals (Item 9)

  • 相关阅读:
    h5 穿透滚动
    Safari 导航栏
    浮层滚动问题
    兼容性常规检测
    CORS
    Webpack 一些概念
    01 离散时间信号的时域表示
    03 信道容量
    01 MATLAB基本概念
    02 字斟句酌
  • 原文地址:https://www.cnblogs.com/linkarl/p/5532244.html
Copyright © 2011-2022 走看看