java 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();

/**
 * 唤醒在这个对象的监视器上等待的所有线程。
 */
public final native void notifyAll();

/**
 * 使当前线程等待. 以毫秒为单位等待的最大时间。
 */
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 >= 500000 || (nanos != 0 && timeout == 0)) {
        timeout++;
    }

    wait(timeout);
}

/**
 * 使当前线程等待,直到另一线程调用
 */
public final void wait() throws InterruptedException {
    wait(0);
}

/**
 * 当垃圾回收确定没有对对象的引用时,垃圾回收器对对象调用。子类重写Fiel化方法来处理系统资源或执行其他清理。
 */
protected void finalize() throws Throwable { }

猜你喜欢

转载自blog.csdn.net/baidu_36327010/article/details/80309232
今日推荐