How to generate a hashcode from object with two list containing the same type of objects

Let's say I have a class (the equal method also exists):

public class SomeClassA { private int a; private int b; @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + a; result = prime * result + b; return result; } }

And another class:

public class SomeClassB { List<SomeClassA> firstList; List<SomeClassA> secondList;

How do I construct the hashcode so that two objects are seen as equals if they have the same objects in firstList and the same objects in secondList.

//Hank

-------------Problems Reply------------

public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + firstList.hashCode();
result = prime * result + secondList.hashCode();
return result;
}

Category:java Views:3 Time:2018-11-07

Related post

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.106 (s). 11 q(s)