Everything is in the title, thanks :)
package com.codegym.task.task24.task2410;
import java.util.LinkedList;
import java.util.List;
/*
Refactoring, anonymous classes
*/
public class Solution {
public static List<Iterator> iterators = new LinkedList<>();
private int itemCount;
public Iterator getIterator(final String name) {
return new Iterator() {
{
Solution.this.itemCount++;
System.out.println(name + "item" + Solution.this.itemCount);
}
public Iterator next() throws CloneNotSupportedException {
return (Iterator) this.clone();
}
};
}
public static void main(String[] args) throws CloneNotSupportedException {
Solution solution = new Solution();
Iterator iterator = solution.getIterator("iterator");
for (int i = 1; i < 5; i++) {
iterators.add(iterator.next());
}
}
}