// 返回类的 Class信息,我们可以通过该 Class 信息 结合 反射技术 拿到Class中 注解 接口 属性等信息.
public final native Class<?> getClass();
// 返回对象的 HashCode,为了更好的支持HashCode,例如 Java中的HashMap
// 其实 我们在以往的面试中 会遇到 “重写了equals方法 为啥要重写hashCode 方法”
// 我们将对象放置到HashMap集合中时 依赖于HashCode的值,然后经过散列算法后,确定位置。
// 但是 如果我们重写了equals方法,没有重写hashCode的话,会造成两个相同的HashCode,但是内容不同。
public native int hashCode();
// 比较两个对象 是否相同,在不重写该方法的情况下,还是使用 == 来进行比较
public boolean equals(Object obj) {
// 但是该 克隆的方式以 浅复制 的方式创建一个对象
protected native Object clone() throws CloneNotSupportedException;
// 返回对象内容,但是可以以重写的方式返回其详细内容
public String toString() {
return getClass().getName() + "@" + Integer.toHexString(hashCode());
// 当某个线程持有当前对象锁时,可以执行对象锁.wait,将持有对象锁的线程挂起等待。
public final native void wait(long timeoutMillis) throws InterruptedException;
// 当某个线程持有当前对象锁时,可以执行对象锁.notify,唤醒之前基于wait挂起的一个线程。
public final native void notify();
public final native void notifyAll();
public final void wait() throws InterruptedException {
public final void wait(long timeoutMillis, int nanos) throws InterruptedException {
if (timeoutMillis < 0) {
throw new IllegalArgumentException("timeoutMillis value is negative");
if (nanos < 0 || nanos > 999999) {
throw new IllegalArgumentException(
"nanosecond timeout value out of range");
// 当触发垃圾回收时,如果当前对象无法基于可达性分析定位到,就会被垃圾回收器回收掉,
// 在回收之前,如果这个对象重写了finalize,那就会触发finalize方法执行。可以执行一些其他的清理工作。
// (Finalize在JVM中,他不保证一定执行,他用的守护线程)
protected void finalize() throws Throwable { }