object is the parent class of all classes, and any class inherits object by default. What exactly does the object class implement?
1. Clone method
Protection method, implement shallow copy of object, only implement the Cloneable interface can call this method, otherwise throw clonenotsupportedexception exception.
Basically Java in addition to 8 basic types of parameters is the value of the transfer, the other class object parameters are reference passing, we sometimes do not want to say in the method parameter changes, this is the need to replicate the Clone method in the class.
2. GetClass method
Final method, which gets the run-time type.
3. ToString Method
This method is used more and the general subclass has coverage.
4. Finalize method
This method is used to release resources. It is seldom used because it is not possible to determine when the method is invoked.
5. Equals method
This method is a very important method. The general equals and = = are not the same, but the two are the same in object. Subclasses generally have to override this method.
6. Hashcode method
This method is used for hash lookups, and overriding the Equals method generally overrides the Hashcode method. This method is used in some collection with hash functions.
The Obj1.equals (OBJ2) ==true must be met in general. Obj1.hash-code () ==obj2.hashcode () can be introduced, but hashcode equality does not necessarily satisfy equals. However, in order to improve efficiency, we should try to make the above two conditions nearly equivalent.
7. Wait method
The wait method is to have the current thread wait for the lock on the object, which must be the owner of the object, which is the lock that owns the object. The wait () method waits until the lock is acquired or interrupted. Wait (long timeout) sets a time-out interval that returns if the lock is not acquired within the specified time.
When the method is called, the thread goes to sleep until the following event occurs.
(1) The Notify method of the object is called by other threads.
(2) The Notifyall method of the object is called by other threads.
(3) Another thread called Interrupt interrupts the thread.
(4) The time interval is up.
At this point the thread can be dispatched, and if it is interrupted, throws a Interruptedexception exception.
8. Notify method
The method wakes up a thread waiting on the object.
9. Notifyall method
The method wakes up all the threads waiting on the object.
What are the common methods of object?