一、概述

1、介绍

  Object 类属于 java.lang 包,此包下的所有类在使用时无需手动导入,系统会在程序编译期间自动导入。
  Object 类是所有类的基类,如果一个类没有使用 extends 标识继承另外一个类,那么这个类默认继承Object类。任何类都直接或间接继承此类。

  类结构图:

JDK1.8源码(一)——java.lang.Object类

  代码示例:Object类源码

 1 public class Object {
 2 
 3     private static native void registerNatives();
 4     static {
 5         registerNatives();
 6     }
 7 
 8     public final native Class<?> getClass();
 9 
10     public native int hashCode();
11 
12     public boolean equals(Object obj) {
13         return (this == obj);
14     }
15 
16     protected native Object clone() throws CloneNotSupportedException;
17 
18     public String toString() {
19         return getClass().getName() + "@" + Integer.toHexString(hashCode());
20     }
21 
22     public final native void notify();
23 
24     public final native void notifyAll();
25 
26     public final native void wait(long timeout) throws InterruptedException;
27 
28     public final void wait(long timeout, int nanos) throws InterruptedException {
29         if (timeout < 0) {
30             throw new IllegalArgumentException("timeout value is negative");
31         }
32 
33         if (nanos < 0 || nanos > 999999) {
34             throw new IllegalArgumentException(
35                                 "nanosecond timeout value out of range");
36         }
37 
38         if (nanos > 0) {
39             timeout++;
40         }
41 
42         wait(timeout);
43     }
44 
45     public final void wait() throws InterruptedException {
46         wait(0);
47     }
48 
49     protected void finalize() throws Throwable { }
50 }
Object类源码

相关文章:

  • 2021-06-05
  • 2021-06-02
  • 2021-08-11
  • 2021-11-05
  • 2021-08-09
猜你喜欢
  • 2022-01-23
  • 2021-08-14
  • 2022-01-27
  • 2021-12-01
  • 2021-09-08
  • 2021-12-15
  • 2021-07-27
相关资源
相似解决方案