JDK8-Object源码,架构师必读书籍推荐

本文详细解析了Java中Object类的源码,包括getClass(), equals(), hashCode(), clone()以及wait(), notify(), notifyAll()等核心方法的实现和使用场景。这些方法对于理解和实现Java对象的创建、比较、复制以及线程同步至关重要,是进阶Java程序员和架构师必备的知识。" 125455011,7493313,二选一逻辑选择器:Multisim与FPGA实现,"['fpga开发', '逻辑器', '二选一', '硬件设计', '数字电路']
摘要由CSDN通过智能技术生成

*/

package java.lang;

/**

  • Class {@code Object} is the root of the class hierarchy【类层次结构,等级】.

  • Every class has {@code Object} as a superclass. All objects,

  • including arrays, implement the methods of this class.

  • @author unascribed

  • @see java.lang.Class

  • @since JDK1.0

*/

public class Object {

private static native void registerNatives();

static {

registerNatives();

}

/**

  • Returns the runtime class of this {@code Object}. The returned

  • {@code Class} object is the object that is locked by {@code

  • static synchronized} methods of the represented class.

  • The actual result type is {@code Class<? extends |X|>}

  • where {@code |X|} is the erasure of the static type of the

  • expression on which {@code getClass} is called. For

  • example, no cast is required in this code fragment:

  • {@code Number n = 0; }

  • {@code Class<? extends Number> c = n.getClass(); }

  • @return The {@code Class} object that represents the runtime

  •     class of this object.
    
  • @jls 15.8.2 Class Literals

*/

public final native Class<?> getClass(); //返回一个对象的运行时类,通过返回的类对象可以获取运行时类的相关属性和方法,就是java的反射机制

/**

  • Returns a hash code value for the object. This method is

  • supported for the benefit of hash tables such as those provided by

  • {@link java.util.HashMap}.

  • The general contract of {@code hashCode} is:

    • Whenever it is invoked on the same object more than once during
    • an execution of a Java application, the {@code hashCode} method
      
    • must consistently return the same integer, provided no information
      
    • used in {@code equals} comparisons on the object is modified.
      
    • This integer need not remain consistent from one execution of an
      
    • application to another execution of the same application.
      
    • If two objects are equal according to the {@code equals(Object)}
    • method, then calling the {@code hashCode} method on each of
      
    • the two objects must produce the same integer result.
      
    • It is not required that if two objects are unequal
    • according to the {@link java.lang.Object#equals(java.lang.Object)}
      
    • method, then calling the {@code hashCode} method on each of the
      
    • two objects must produce distinct integer results.  However, the
      
    • programmer should be aware that producing distinct integer results
      
    • for unequal objects may improve the performance of hash tables.
      
    • As much as is reasonably practical, the hashCode method defined by

    • class {@code Object} does return distinct integers for distinct

    • objects. (This is typically implemented by converting the internal

    • address of the object into an integer, but this implementation

    • technique is not required by the

    • Java™ programming language.)

    • @return a hash code value for this object.

    • @see java.lang.Object#equals(java.lang.Object)

    • @see java.lang.System#identityHashCode

    • */

      public native int hashCode(); //返回对象的散列码

      /**

      • Indicates【表明】 whether some other object is “equal to” this one.

      • The {@code equals} method implements an equivalence relation

      • on non-null object references:

        • It is reflexive: 【自反性】f
      评论
      添加红包

      请填写红包祝福语或标题

      红包个数最小为10个

      红包金额最低5元

      当前余额3.43前往充值 >
      需支付:10.00
      成就一亿技术人!
      领取后你会自动成为博主和红包主的粉丝 规则
      hope_wisdom
      发出的红包
      实付
      使用余额支付
      点击重新获取
      扫码支付
      钱包余额 0

      抵扣说明:

      1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
      2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

      余额充值