public class ArrayOfLinksDemo { private class Node { public T val; public Node next; public Node() { val = null; next = null; } public Node(T v) { val = v; next = null; } } // What we want is an array of Nodes. However, Java will choke on the // generics. So we have to declare it as an array of Objects, and then // cast these objects as Nodes when we pull them out of the array. private Object[] arr; public ArrayOfLinksDemo() { arr = new Object[10]; } public void bar(T x) { // Since Object is a superclass of Node (since it's a superclass of // everything), we can assign Objects to be Node with no extra fanfare. arr[3] = new Node(x); } public void zap(T x) { // When we pull something out of the array, though, Java sees it just as // an Object. We know that the only things we put in the array are // actually Nodes, though, so we're okay casting them as such. @SuppressWarnings("unchecked") Node n = (Node) arr[3]; // Now we can use the data and methods of Node, like .next . n.next = new Node(x); } public T wakka() { // Same again here: when we read something out of the array, we need to // cast it before we can use it as a Node. @SuppressWarnings("unchecked") Node n = (Node) arr[3]; return n.val; } public static void main(String[] args) { // Hooray! Now everything works just like we want it to. ArrayOfLinksDemo foo = new ArrayOfLinksDemo(); foo.bar("Waz"); foo.zap("Huj"); System.out.println(foo.wakka()); } }