@@ -1118,17 +1118,28 @@ abstract class AbstractStringBuilder implements Appendable, CharSequence {
1118
1118
1119
1119
Object 类是一个特殊的类,是所有类的父类。它主要提供了以下 11 个方法:
1120
1120
1121
- - ` public final native Class<?> getClass() ` :` native ` 方法,用于返回当前运行时对象的` Class ` 对象,使用了` final ` 关键字修饰,故不允许子类重写
1122
- - ` public native int hashCode() ` :` native ` 方法,用于返回对象的哈希码,主要使用在哈希表中,比如` HashMap `
1123
- - ` public boolean equals(Object obj) ` :用于比较两个对象的内存地址是否相等,` String ` 类对该方法进行了重写,判断用户比较字符串的值是否相等
1124
- - ` protected native Object clone() throws CloneNotSupportedException ` :` naitive ` 方法,用于创建并返回当前对象的一份拷贝。一般情况下,对于任何对象` x ` ,表达式` x.clone() != x ` 为` true ` ,` x.clone().getClass() == x.getClass() ` 为` true ` 。` Object ` 本身没有实现` Cloneable ` 接口,所以不重写` clone ` 方法并且进行调用的话会发生` CloneNotSupportedException ` 异常
1125
- - ` public String toString() ` :返回` 类的名字@实例的哈希码 ` 的16进制的字符串。建议` Object ` 所有的子类都重写这个方法
1126
- - ` public final native void notify() ` :` native ` 方法,并且不能重写。唤醒一个在此对象监视器上等待的线程(监视器相当于就是锁的概念),如果有多个线程在等待只会任意唤醒一个
1127
- - ` public final native void notifyAll() ` :` native ` 方法,并且不能重写。跟` notify ` 一样,唯一的区别就是会唤醒在此对象监视器上等待的所有线程,而不是一个线程
1128
- - ` public final native void wait(long timeout) throws InterruptedException ` :` native ` 方法,并且不能重写。暂停线程的执行。注意:` sleep ` 方法没有释放锁,而` wait ` 方法释放了锁 ,` timeout ` 是等待时间
1129
- - ` public final void wait(long timeout, int nanos) throws InterruptedException ` :多了` nanos ` 参数,这个参数表示额外时间(以毫微秒为单位,范围是` 0-999999 ` ), 所以超时的时间还需要加上` nanos ` 毫秒
1130
- - ` public final void wait() throws InterruptedException ` :跟之前的2个` wait ` 方法一样,只不过该方法一直等待,没有超时时间这个概念
1131
- - ` protected void finalize() throws Throwable { } ` :实例被垃圾回收器回收的时候触发的操作
1121
+ ``` java
1122
+ public final native Class<?> getClass()// native方法,用于返回当前运行时对象的Class对象,使用了final关键字修饰,故不允许子类重写。
1123
+
1124
+ public native int hashCode() // native方法,用于返回对象的哈希码,主要使用在哈希表中,比如JDK中的HashMap。
1125
+ public boolean equals(Object obj)// 用于比较2个对象的内存地址是否相等,String类对该方法进行了重写用户比较字符串的值是否相等。
1126
+
1127
+ protected native Object clone() throws CloneNotSupportedException // naitive方法,用于创建并返回当前对象的一份拷贝。一般情况下,对于任何对象 x,表达式 x.clone() != x 为true,x.clone().getClass() == x.getClass() 为true。Object本身没有实现Cloneable接口,所以不重写clone方法并且进行调用的话会发生CloneNotSupportedException异常。
1128
+
1129
+ public String toString()// 返回类的名字@实例的哈希码的16进制的字符串。建议Object所有的子类都重写这个方法。
1130
+
1131
+ public final native void notify()// native方法,并且不能重写。唤醒一个在此对象监视器上等待的线程(监视器相当于就是锁的概念)。如果有多个线程在等待只会任意唤醒一个。
1132
+
1133
+ public final native void notifyAll()// native方法,并且不能重写。跟notify一样,唯一的区别就是会唤醒在此对象监视器上等待的所有线程,而不是一个线程。
1134
+
1135
+ public final native void wait(long timeout) throws InterruptedException // native方法,并且不能重写。暂停线程的执行。注意:sleep方法没有释放锁,而wait方法释放了锁 。timeout是等待时间。
1136
+
1137
+ public final void wait(long timeout, int nanos) throws InterruptedException // 多了nanos参数,这个参数表示额外时间(以毫微秒为单位,范围是 0-999999)。 所以超时的时间还需要加上nanos毫秒。
1138
+
1139
+ public final void wait() throws InterruptedException // 跟之前的2个wait方法一样,只不过该方法一直等待,没有超时时间这个概念
1140
+
1141
+ protected void finalize() throws Throwable { }// 实例被垃圾回收器回收的时候触发的操作
1142
+ ```
1132
1143
1133
1144
1134
1145
## 反射
0 commit comments