1.Object类源码解析
Object 是所有类的基类,很重要。
1.

这是第一个方法,用static ,native修饰,意思是一个本地方法,具体是用C(C++)在DLL中实现的,然后通过JNI调用,然后使用static 静态代码块,在对象初始化时自动调用该方法。
2.

返回运行时的类,意思就是说类对象的运行时类的Class对象。可以看到这个方法使用final 修饰,所以他不能被子类覆盖。当你这样写:super.getClass().getName()的时候并不会返回他老爸的类,只会返回运行时的类
3.

返回hashCode。博主在看源码的时候才发现其实hashCode返回的是一个int 类型,博主一直以为是一个String类型,hashCode 一个用途是在equals()比较的时候,当两个对象 equals()为True 那么这两个类的hashCode 值一定相同,但是当两个hashCode 值相同的时候,equals()却不一定为true,所以有时候如果需要循环equals比较的时候,其实可以先取hashCode 比较一下如果hashCode都不一样那么equals ()一定不一样,没必要往下走,这样可以提高效率,因为hashCode 的执行效率要比equals 要高。
4.

判断两个object是否相等主要有如下四个特性(对于任何非空引用值 x 和 y):自反性:x.equals(x) = true。对称性:y.equals(x) = true 时,x.equals(y) = true,传递性:如果 x.equals(y) =true,y.equals(z)=true, 那么 x.equals(z) =true,一致性:当比较的东西没有被修改时,多次调用 x.equals(y) 始终返回 true 或始终返回 false.
5.

clone方法,首先他有一个CloneNotSupportedException异常,所有被克隆的类一定要实现Cloneable 接口否则会抛出这个异常,Cloneable没有具体实现,要想实现必须自己手动实现 。当然数组类型默认都是实现的(这里的克隆其实是浅拷贝,不是深拷贝)。还有一点他是protected 类型,也就是说在一个包中和public是一样的,但是在包外使用要注意。
6.

tostring(),默认返回的是对象的字符串表达形式也就是(对象名和hashcod码),一般情况下都是会去重写它的。
7.





这里我们把notify()、notifyAll()、wait() 放一起讲,首先wait()方法就是说将该对象的控制权握在自己手里,一直处于等待状态,直到被notify()或者notifyAll()唤醒,这几个方法主要为线程同步而准备的。notify()如果被调用,就会唤醒别的线程(随随机一个)去继续运行该对象,notifyAll()如果被调用,所有等待该对象的控制器线程继续运行。
8.

finalize(),可以理解为在GC垃圾回收的时候执行该方法。
PS:哪里不对可以在评论中指出,我都会一个个看的,觉得少东西也可以评论中提出来,我会做补充。