You can use between any List <...> - s, protection is weaker than usual.
try it
List<String> a = new Vector<String>(); List<Integer> b = new Vector<Integer>(); Integer i = new Integer(0); b.add(2); a = (List<String>) (Object) b; System.out.println((Object)a.get(0));
there will be no exceptions.
This is because generics is only compilation time.
If you write
System.out.println(a.get(0));
you will get a ClassCastException because the version of the println version defined at compile time will be println (String arg).
And so the answer to the question: it is wrong to have such an alternative.
Dims
source share