Reputation: 79
I am looking in to the java queue and i stuck in this line "Queue implementations generally do not define element-based versions of the equals and hashCode methods but instead inherit the identity-based versions from Object."
1.need the complete meaning of the above text.
2.what is element based versions of the equals and hashcode -- what it refers to ?
3.Identity based versions -- what does this mean ?
4. is Version belong to class or object / who's version and where it will be ?
URL :https://docs.oracle.com/javase/tutorial/collections/interfaces/queue.html
Upvotes: 2
Views: 541
Reputation: 394106
It means that standard implementations of the Queue
interface usually don't override equals
and hashCode
methods of the Object
class, which means the default implementation of Object
class is used (i.e. the identity-based version which simply uses ==
for equals
).
Element based versions of equals
and hashCode
would determine if two Collection
s are equal and calculate hashCode
based on the elements contained in the Collection
, which is why it is called "Element based".
For example, ArrayList
(or actually its super-class AbstractList
) overrides equals
in a way that two List
s are equal to each other if they have the same number of elements and the elements are equal to each other (in the order in which they appear). The hashCode
is a function of the hashCode
s of all the elements.
Upvotes: 4