package java.lang;
//基于jdk1.8
public class Object {
public Object() {
}
private static native void registerNatives();
//注册底层,暂时没有更多的了解
public final native Class<?> getClass();
//获取class对象,final修饰,不允许重写
public native int hashCode();
//计算hash值的方法
public boolean equals(Object var1) {
//判断两个对象是否相等,本质还是对比两个对象的地址值,一般会重写
return this == var1;
}
protected native Object clone() throws CloneNotSupportedException;
//浅拷贝方法,对应类有实现,如ArrayList
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;
//多线程中,释放对象锁,并释放资源和CPU占有
public final void wait(long var1, int var3) throws InterruptedException {
//timeout :最大等待时间(毫秒)。nanos :附加时间在毫微秒范围0-999999。
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 Object类方法与属性解析
最新推荐文章于 2023-08-28 23:23:45 发布