zhujiangtaotaise 2020-04-16
有好些都是native本地方法,背后是C++写的

没有关于构造器的描述,默认编译器提供的无参构造
https://blog.csdn.net/dmw412724/article/details/81477546
啊,为什么还是native。目前只能得出的结论是 凡是native修饰的方法,都是JNI调用C++或者C的代码实现的
获取类对象,用于反射和读取配置文件之类的
public final native Class<?> getClass();
获取对象的哈希值,类似C的地址值,由于是在JVM运行的,所以并不是真实的内存地址值,是虚拟的
- 可用于辅助判断两个对象是否是一样的
public native int hashCode();
原汁原味的equal判断,直接取地址比较
public boolean equals(Object obj) {
return (this == obj);
}克隆方法,返回一个复制出来的对象,除了new方式的第二种获取对象的办法
- 注意 不支持克隆异常 ,此方法需要实现Cloneable接口才可用使用
protected native Object clone() throws CloneNotSupportedException;
默认的toString方法
- 返回的是 对象所属的类的完整类名 和 转换成16进制的哈希值
public String toString() {
return getClass().getName() + "@" + Integer.toHexString(hashCode());
}多线程开发所用,方法意思通知
【通知一个在对象上等待的线程,使其从wait方法中返回,返回需要获取到该对象的锁 】
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 > 0) {
timeout++;
}
wait(timeout);
}【进入等待状态,直至被其他线程通知,或者中断 才返回】
public final void wait() throws InterruptedException {
wait(0);
}【对象被销毁时执行的方法】
protected void finalize() throws Throwable { }