所有的java类均继承Object类, package java.lang; public class Object { public Object() { } private static native void registerNatives(); public final native Class<?> getClass(); public native int hashCode(); /*比较两个对象是否相等,实际上比较的是两个对象的引用*/ public boolean equals(Object var1) { return this == var1; } /*克隆*/ protected native Object clone() throws CloneNotSupportedException; public String toString() { return this.getClass().getName() + "@" + Integer.toHexString(this.hashCode()); } public final native void notify(); public final native void notifyAll(); public final native void wait(long var1) throws InterruptedException; /*线程等待,实际上传入了纳秒后毫秒就自增1,精度实际还是纳秒*/ public final void wait(long var1, int var3) throws InterruptedException { if (var1 < 0L) { throw new IllegalArgumentException("timeout value is negative"); } else if (var3 >= 0 && var3 <= 999999) { if (var3 > 0) { ++var1; } this.wait(var1); } else { throw new IllegalArgumentException("nanosecond timeout value out of range"); } } public final void wait() throws InterruptedException { this.wait(0L); } /*垃圾回收前要做的操作,一般来说都会重写这个方法*/ protected void finalize() throws Throwable { } static { registerNatives(); } }
java源码分析——java.lang.Object
最新推荐文章于 2021-09-16 11:46:43 发布