In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail what methods the Object class in Java Review consists of. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
Introduction to Object class
The Object class is the base class of all java classes, and all classes inherit from it.
Method composition
GetClass ()
Used to get runtime class objects
ToString ()
When an object of a type is printed out or spliced with a string type, the object of this type will automatically call the toString () method to convert it to a string type and then carry out subsequent operations. If this type does not implement the toString method itself, it will call the Object class. By default, it returns the ClassName+'@'+ of this class, an unsigned hexadecimal calculated as a parameter.
Equals (obj)
A very important method to judge whether an object is equal to an object. Note: equals is not the same as = =. Equals only judges whether the value of the object is equal. In addition to judging the value of the object, you also need to judge whether the memory address of the object is the same Note: the parameter of equals is of type Object.
HashCode ()
This method returns the hash value of the object, which is mainly used for object hash lookup in some collection classes (such as HashMap). It needs to be emphasized that this method is a pair with equals, the object rewriting equals method must also rewrite the hashcode method, and the same attribute is selected for operation theorem: two objects of equals must be equal in hashCode, and two objects with equal hashCode may not necessarily be equals.
Wait ()
It is used to pause the thread holding the object, give up resources, and let the current thread enter the waiting state, which is essentially different from the sleep method of Thread. The wait method allows the thread to enter the waiting state and does not occupy the object resources at this time, while other threads can occupy the object, while the sleep method is occupying the object resources and other threads can only wait and wait. The thread enters the state after wait and so on. If you want to enter the scheduling state again, you need to wake up in the following ways, 1. The wait time set by calling the notify or notifyAll method 2.wait () method is 3. 0. Other threads called the interrupt thread method interrupt method
Notify ()
Used to wake up a thread waiting on an object
NotifyAll ()
Used to wake up all threads waiting on the object
Clone ()
Shallow copy method, which is used to quickly create an object, but because it is a shallow copy, the created object will change, and the original object will also change. If a deep copy is needed, the subclass needs to override the clone method. The method returns an instance object that is re-new.
Finalize ()
Used to release resources, but because it is impossible to know when to call back to release, this method is rarely used in reality
This is the end of this article on "which methods are made up of Object classes in Java Review". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it out for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.