I'm trying to write a Java function which takes a List
of List
s holding objects of any class, and then calculates the size of the set consisting of all different combinations of inner list objects, where all objects come from different lists. The algorithm is simple:
int combos(List<List<Object>> inList) {
int res = 1;
for(List<Object> list : inList) {
res *= list.size();
}
return res;
}
But I'm getting this error when trying to run the function with a List<List<Integer>>
object as input parameter:
List<List<Integer>> input = new ArrayList<List<Integer>>();
input.add(new ArrayList<Integer>());
input.get(0).add(1);
input.get(0).add(2);
combos(input);
The error:
The method combos(List<List<Object>>) in the type SpellChecker is not applicable for the arguments (List<List<Integer>>)
As far as I understand, Object
is the parent class of Integer
. So why doesn't this work? How can I make it work?