I have a data structure containing a list of objects, like this:
class A {
private List<Object> list;
}
How to properly define a hash function for the list, assuming each element of the list has a correct hashCode()?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If the actual
Listimplementation is fully conformant to the interface, the providedhashCodeimplementation should be sufficient:(List documentation)
The
Listinterface requires conforming implementations to provideequalsbased on the elements of the list. Thus, they had to specify thehashCodealgorithm explicitely