public interface Inteator {
boolean hasNext();
Object next();
}
public interface Iterable {
Iterator iterator();
}
public interface Collection extends Iterable {
Iterator iterator();
}
public interface List extends Collection {
Iterator iterator();
}
public class ArrayList implements List {
public Iterator iterator() {
return new Itr();
}
private class Itr implements Iterator {
public boolean hasNext() {}
public Object next(){}
}
}
Collection c = new ArrayList();
c.add("hello");
c.add("world");
c.add("java");
Iterator it = c.iterator(); //new Itr();
while(it.hasNext()) {
String s = (String)it.next();
System.out.println(s);
}
所以说在真正的具体子类中,以内部类的方式体现
本文出自 “GD” 博客,转载请与作者联系!
原文地址:http://wangdenghui.blog.51cto.com/9930072/1768707