当前位置:网站首页>Summary of common methods of object class (September 14, 2020)

Summary of common methods of object class (September 14, 2020)

2022-07-07 23:29:00 codepig16

1.clone()
Protection method , Implement shallow copy of objects ..
Only realized Cloneable Interface , To call this method ,
Otherwise throw CloneNotSupportedException abnormal .

2.getClass()
final Method
Get runtime type .

3.finalize()
Release resources .
It is uncertain when this method will be called .

4.toString()
In general, subclasses have coverage .

5.equals()
In general, subclasses have coverage .
stay Object in ,equals and == It's the same .

6.hashCode()
For hash lookup , You can reduce the use of equals The number of times .
rewrite equals() It's usually rewritten hashCode().
equals identical ,hashCode() Same value .
hashCode Equality is not necessarily satisfied equals.

7.wait()
wait The method is to make the current thread wait for the lock of the object ,
The current thread must be the owner of the object , That is, the lock with the object .
wait() Method has been waiting for , Until the lock is obtained or interrupted .
wait(long timeout) Set a timeout interval , If the lock is not obtained within the specified time, return .
After calling this method, the current thread goes to sleep , Until .
(1) Other threads called the object's notify Method .
(2) Other threads called the object's notifyAll Method .
(3) Other threads called interrupt Interrupt the thread .
(4) Time's up .
At this point, the thread can be scheduled , If it is interrupted, throw a InterruptedException abnormal .

8.notify()
The method wakes up on the object , A thread waiting .

9.notifyAll()
The method wakes up on the object , All threads waiting .

原网站

版权声明
本文为[codepig16]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202130559466215.html