Type safety and Generics

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.

Leave a Reply