Type safety and Generics
Sunday, 14 August 2005
I had a relevation what type-safety is all about when Tim Bray posted the following code snippet:
public interface Page<K extends Comparable<K>>
public class LocalPage<K extends Comparable<K>> implements Page<K>
Pair<K>[] p = (Pair<K>[]) new Pair[size];
It makes the language crash-proof by making it impossible to start. All this complication just to avoid the remote possibility a programmer might try to compare a bicycle with a fish.
In one swoop, generics has become a compulsory element in Java; basic Java courses will never be same again.