for loop
public class Main {
public static void main(String[] args) throws Exception {
Balls b = new Balls() {
List l = new ArrayList<Integer>();
{
l.add(1);
l.add(2);
l.add(3);
l.add(4);
}
Iterator<Integer> i = l.iterator();
public Integer next() {
return i.hasNext() ? i.next() : null;
}
};
for (Integer i = b.next(); i != null; i = b.next()) {
System.out.println("works :" + i);
}
}
interface Balls {
Integer next();
}
}
zobrazení: