![]() |
VOOZH | about |
The hashCode() method of the java.lang.reflect. Method class returns a hash code value for a Method object. This hash code is computed using the method's name and its declaring class name. It is commonly used in hashing-based collections such as HashMap, HashSet, and Hashtable to efficiently store and retrieve method-related information.
public int hashCode()
Example 1: Get the hash code of a specific method object created by calling getDeclaredMethod() of Class object.
hashCode of method getSampleMethod is 1553813225
Explanation: In this example, the getDeclaredMethod() method is used to obtain the Method object representing getSampleMethod(). The hashCode() method is then called on this Method object to retrieve its hash code value. Finally, the program prints the method name along with its corresponding hash code.
Example 2: Program Demonstrate hashcode() method of Method Class.
hashCode of method main is 3282673 hashCode of method getSampleMethod is 1553813225 hashCode of method setSampleMethod is -1830532123 hashCode of method equals is -1918826964 hashCode of method toStri...
Explanation: Output of this program also showing results for method objects other than methods defined in class object like wait, equals, toString, hashCode, getClass, notify, and notifyAll, which are inherited from superclass Object of java.lang package by class Object.
hashCode() Method