interface Iterator<E> { E next(); boolean hasNext(); } interface ImmutableList<E> { //void add(E x); Iterator<E> iterator(); } class StupidList<E> implements ImmutableList<E> { private E e; public void add( E e ){ this.e = e; } public Iterator<E> iterator(){ return new Iterator<E>(){ public E next(){ return e; } public boolean hasNext(){ return true; } }; } } class G7 { public static void main( String[] args ){ StupidList<String> stupidList = new StupidList<String>(); stupidList.add("Cool stuff"); ImmutableList<String> sList = stupidList; // subtyping // sList.add("Cool stuff"); // disallowed for( Iterator<String> it = sList.iterator(); it.hasNext(); ){ String s = it.next(); System.out.println(s); } // no "immutable" concept in Collections Framework ImmutableList<Object> oList = sList; // still compilation error, however // oList.add(new Object()); // disallowed for( Iterator<String> it = sList.iterator(); it.hasNext(); ){ String s = it.next(); System.out.println(s); } } }