/* // generic code class Vector<T> { private T e; void set( int i, T e ){ this.e = e; } T get(int i){ return e; } } class G1 { public static void main( String[] args ){ Vector<String> v = new Vector<String>(); v.set(0,"Cool stuff"); String s = v.get(0); Vector<Thread> w = new Vector<Thread>(); w.set(0,new Thread()); Thread t = w.get(0); v.set(0,t); w.set(0,"Bad luck"); t = v.get(0); s = w.get(0); } } */ /* class VectorOfString { // this is NOT what happens, but... private String e; void set( int i, String e ){ this.e = e; } String get(int i){ return e; } } class VectorOfThread { private Thread e; void set( int i, Thread e ){ this.e = e; } Thread get(int i){ return e; } } */ class Vector { // This is what happens: type erasure private Object e; void set( int i, Object e ){ this.e = e; } Object get(int i){ return e; } } class G26 { public static void main( String[] args ){ Vector v = new Vector(); v.set(0,"Cool stuff"); String s = (String) v.get(0); Vector w = new Vector(); w.set(0,new Thread()); Thread t = (Thread) w.get(0); v.set(0,t); w.set(0,"Bad luck"); // t = (String) v.get(0); s = (Thread) w.get(0); } }