I am having some trouble creating a for loop within a constructor to iterate over a map and an array at the same time. Here, it is indicated that this cannot be done with an enhanced for loop.
I have something like this, which raises a compiler error. Basically, the class has a Map which I want to populate via the constructor which takes a collection and a variable number of integers as parameters.
The var-arg expression evaluates to an array of integers, so I tried to put both enhanced iterators in the same loop, but didn t work.
private final Map<Module, Integer> modules = new HashMap<Module, Integer>();
AssemblyType(Collection<Module> modules, int... units) {
int i = 0;
for (Module module : modules, int i : units) {
this.modules.put(module, units[i]);
}
}
Thanks for any ideas on how to proceed.