Java. Lang. Object

Source: Internet
Author: User

Package java. Lang;

/**
*
* An object is the parent class of all objects, including common objects and array objects.
*
* Comment by liqiang
*
*/
Public class object {

Private Static native void registernatives ();
Static {
Registernatives ();
}

/**
*
* Obtain the class object corresponding to the current object
* There are three main methods to obtain the Class Object:
* 1 object. getclass ()
* 2 string. Class;
* 3 class clazz = Class. forname ("AA. BB ");
*
* @ Return the class object corresponding to the current object
*
*/
Public final native class getclass ();

/**
*
* Returns the hashcode of the current object.
* Note: 1. the same object calls this method multiple times to obtain the same value.
* 2 if two objects call the equals method and return true, their hashcode should also be the same
* 3 if two objects call the equals method and return false, their hashcode is not necessarily different.
* The current hashcode value is an int value converted from the memory address.
*
*
* @ Return hashcode Value
*
*/
Public native int hashcode ();

/**
*
* Determine whether two objects are equal
*
* Features:
* X is not null.
* 1 reflexive (self-inverse) X. Equals (x) = true hengcheng Li
* 2 until RIC (Symmetry) X. Equals (y) = true, then Y. Equals (x) = true
* 3 transitive (pass-through) If X. Equals (y) = true, Y. Equals (z) = true, X. Equals (z) = true
* 4 consistent (consistency) If X. Equals (y) = true, true is returned no matter how many calls
* 5 X. Equals (null) is false
*
* The default Implementation of the object is to compare the memory address.
* If the subclass overrides this method, it is best to override the hashcode method to ensure that the two objects are equal, the hashcode is also equal.
*
* @ Param OBJ: object to be compared
* @ Return equal return true unequal return false
*
*/
Public Boolean equals (Object OBJ ){
Return (this = OBJ );
}

/**
*
* The clone object is returned. To call this method, the cloneable interface must be inherited.
* Otherwise, clonenotsupportedexception is thrown.
*
*/
Protected native object clone () throws clonenotsupportedexception;

/**
*
* String representation of an object
*
* @ Return indicates the string of the object.
*
*/
Public String tostring (){
Return getclass (). getname () + "@" + integer. tohexstring (hashcode ());
}

/**
*
* This method wakes up a thread waiting for the lock of object A and gives it the right to compete for the lock of object a again.
* At the same time, only one thread can own the Lock of an object.
* The lock that a thread can own an object is to call the synchronization method, 2 synchronization blocks, and 3 static Synchronization Methods in 1. Pay attention to static Synchronization Methods.
* Locking class objects
* Watie and policy must be called when an object A is locked
* The wake-up thread starts to compete for the object lock only when the current thread releases the lock of the object (the synchronization method ends or the synchronization block ends ).
* Although the thread calls the notify method, the lock is not released immediately.
*
* @ Exception if the current thread does not have the lock of object A, it will throw illegalmonitorstateexception
*/
Public final native void Policy ();

/**
*
* Wake up all threads waiting for the lock of object A. These threads will compete for this lock.
*
* @ Exception if the current thread does not have the lock of object A, it will throw illegalmonitorstateexception
*
*/
Public final native void policyall ();

/**
* When the current thread enters the Waite set of object A, the thread will be suspended and the lock of this object will be released.
* The locks of other objects remain in the suspended state, which is also the cause of deadlock.
*
* The thread will be awakened in the following circumstances.
* 1 the other thread that owns the Lock of this object calls the notify method, and the thread is awakened,
* 2 other threads that own the Lock of this object call policyall
* 3 expired
* 4 other threads interrupt this thread
* Then his thread competes for the lock of this thread
*
* Infinite waiting when the time is 0
*
*
* @ Param timeout the number of milliseconds to wait
* @ Exception if the number of Waits is negative, illegalargumentexception is thrown.
* @ Exception if the thread does not obtain the object lock, it will throw illegalmonitorstateexception.
* @ Exception when this thread is interrupted by another thread during Waite, interruptedexception is thrown. When this exception is thrown
* The thread interruption mark will be cleared.
*/
Public final native void wait (long timeout) throws interruptedexception;

/**
*
* Wait for the specified time
*
*/
Public final void wait (long timeout, int Nanos) throws interruptedexception {
If (timeout <0 ){
Throw new illegalargumentexception ("timeout value is negative ");
}

If (Nanos <0 | Nanos> 999999 ){
Throw new illegalargumentexception (
"Nanosecond timeout value out of range ");
}

If (Nanos >=500000 | (Nanos! = 0 & timeout = 0 )){
Timeout ++;
}

Wait (timeout );
}

/**
*
* Unlimited waiting
*
*
*/
Public final void wait () throws interruptedexception {
Wait (0 );
}

/**
*
* This method is called before garbage collection. To clear resources
* The exception thrown in the Finalize method will interrupt recovery, but the exception will be ignored.
*
* @ Throws throwable the <code> exception </code> raised by this method
*/
Protected void finalize () throws throwable {}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.