Issue
In order to obtain the hash code of an object in Java, we use the hashCode()
method.
To access (private) fields in Java, by standard, we are expected to have separate method with get
or set
as prefixes based on the kind of operation the method is performing. So why is this different for the hashCode method?
Solution
The method hashCode()
has been introduced with the first Java version, i.e. officially version 1.0.
The getXXX()
and setXXX()
paradigm was established later as part of the JavaBeans standard. JavaBeans defines a simple yet very useful component model by deriving properties from pairs of getters/setters. JavaBeans was introduced with JDK 1.1.
So hashCode()
predates the getter/setter paradigm.
Answered By - Codo
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.