I am trying to write an itertor for a type of ArrayList, where Number is a class.
I can almost do it, but I get errors:
This is the class definition
public class History implements Iterable<ArrayList<Number>> {
This is the definition of the type I wish to iterate over:
private ArrayList<Number> spins = new ArrayList<Number>();
... and here are the iterator functions:
@Override
public Iterator<ArrayList<Number>> iterator() {
Iterator<ArrayList<Number>> it = new Iterator<ArrayList<Number>>() {
private int currentIndex = 0;
@Override
public boolean hasNext() {
return currentIndex < gethistorySize() && spins.get(currentIndex) != null;
}
@Override
public ArrayList<Number> next() {
return spins.get(currentIndex++); // ** ERROR **
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
};
return it;
}
I get an error at the lines marked ** ERROR **
The error I get is:
Multiple markers at this line - The type of expression must be an array type but it resolved to ArrayLisy - Type mismatch: Cannot convert from Number to ArrayList
I am not quite sure what to return here.
Can anybody help?
Thx