• Object类源码详解(基于jdk1.8.0_261)


    1. Object 简介

    • Object是所有类的超类,包括Arrays类都实现了Object类的方法;

    2. Object UML

    3. Object 源码

    package java.lang;
    public class Object {
        private static native void registerNatives();
        static {
            registerNatives();
        }
        public final native Class<?> getClass();
        public native int hashCode();
        public boolean equals(Object obj) {
            return (this == obj);
        }
        protected native Object clone() throws CloneNotSupportedException;
        public String toString() {
            return getClass().getName() + "@" + Integer.toHexString(hashCode());
        }
        public final native void notify(); //通知第一个wait或最后一个wait的线程继续运行
        public final native void notifyAll(); //通知所有wait的线程依次(可能顺序可能逆序)继续运行
        public final native void wait(long timeout) throws InterruptedException; 
        public final void wait(long timeout, int nanos) throws InterruptedException {
            if (timeout < 0) {
                throw new IllegalArgumentException("timeout value is negative");
            }
            if (nanos < 0 || nanos > 999999) {
                throw new IllegalArgumentException(
                                    "nanosecond timeout value out of range");
            }
            if (nanos > 0) {
                timeout++;
            }
            wait(timeout);
        }
        public final void wait() throws InterruptedException {
            wait(0); //wait(0)主要是为了让线程放锁,让其他线程有机会得到锁 
        }
        protected void finalize() throws Throwable { }
    }
    
    

    4. Object使用示例

    
    
    
  • 相关阅读:
    人的一生为什么要努力 &1
    数据库_数据库系统概论
    电子商务安全
    虚拟专用网技术
    人的一生为什么要努力
    数据备份与恢复技术
    入侵检测技术
    简历模板连接
    防火墙技术
    字节与位
  • 原文地址:https://www.cnblogs.com/ahpucd/p/13326893.html
Copyright © 2020-2023  润新知