Object class has following five non final methods.
1. clone()
2. equals(Object obj)
3. finalize()
4. hashCode()
5. toString()
Every Java class has Object as a superclass so by default all above methods are provided in every java class. In this article we will discuss in detail the concepts of hashCode() method. We will discuss why it is necessary to override hashCode method,Why always override hashCode() if overriding equals() and how we can override them.
The signature of hashCode is:
public int hashCode()
1. clone()
2. equals(Object obj)
3. finalize()
4. hashCode()
5. toString()
Every Java class has Object as a superclass so by default all above methods are provided in every java class. In this article we will discuss in detail the concepts of hashCode() method. We will discuss why it is necessary to override hashCode method,Why always override hashCode() if overriding equals() and how we can override them.
Default implementation of hashCode() in Object class
The signature of hashCode is:
public int hashCode()