
import java.util.*;

public class AnonymousClassExample<E> {
	E[] data;
	int size;
	
	public AnonymousClassExample() {
		data = (E[]) new Object[1000];
		size = 0;
	}
	
	public void add(E e) {
		data[size] = e;
		size += 1;
	}
	
	public WeakIterator<E> iterator = new WeakIterator<E>() {
			int current=-1;
				
			public E next() throws NoSuchElementException {
				if (current == size-1) 
					throw new NoSuchElementException("at end of list");
				else {
					current += 1;
					return data[current];
				}
			}
			
			public boolean hasNext() {
				return !(current == size-1);
			}
	};
	
	public static void main(String[] args) {
		AnonymousClassExample<Integer>L = new AnonymousClassExample<Integer>();
		for (int i = 0; i < 10; i++)
			L.add(3*i+7);
		WeakIterator<Integer> it = L.iterator;
		while (it.hasNext())
			System.out.println(it.next());
	}
}
