2

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

1 Answer 1

4

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 Collections 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 Lists 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 hashCodes of all the elements.

Sign up to request clarification or add additional context in comments.

2 Comments

and about the version i questioned..?
@Deepaksai By versions they are referring to implementations. the identity-based versions from Object are the implementations of equals and hashCode of the Object class.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.