Java Advanced (1) - Object class

Object class nine method which is
1, Clone method
to achieve the object of a shallow copy, only to achieve the Cloneable interface can call this method, otherwise throw a CloneNotSupportedException
Java, parameter passing, in addition to eight basic types are passed by value. Other types of objects are passed by reference.

2, getClass method
final way, a runtime type.

3, toString methods
which use more than, have generally covered subclass.

4, finalize the method
the method for releasing the resources. Because it can not determine which instructions when calling, rarely used.

5, equals method

6, hashCode method
which used to hash lookup, can reduce the frequency of use in the find equals rewriting the equals method generally required to override the hashCode method.
Object does not override hashCode method, in the frame set, it is determined whether the target content is quite 2, such as not override hashCode, default memory address, and therefore a plurality of memory.

7, wait method

8, notify method

9, notifyAll method

Why Object Design nine method
equals, hashCode, clone (object type variable is just a reference, irrelevant to the actual content).
toString (in any language the most widely used are strings of operation, can of course also object string conversion is not imperative).
wait, notify * (java is the first direct high-level language support for multithreading, these methods are not essential, of course, not all java programs require explicit use of multi-threading)
the Finalize (java is also the first to support garbage recycling wit high-level language, this method also granted)
getClass (all java Object class has a corresponding)

Why not designed to abstract Object
to be perfect -

Reference: https://www.jianshu.com/p/a509edc4fc08

Guess you like

Origin blog.51cto.com/4397014/2436892