Eric Burke has recently encountered a tricky Generics puzzle
. In his blog he has published a simp-flied version of the puzzler. Even more interesting than the puzzle are some of the responses that point to Erasure and the fact that you can’t type token for Generic types as a source of the problem.
A reply pointed to an earlier blog entry by Neal Gafter
that puts forth an argument for super type tokens. This is in response to a number of questions regarding this use case of Generics.
You can't add your favorite List to a Favorites because you simply can't make a type token for a generic type. This design limitation is one that a number of people have been running into lately, most recently Ted Neward. "Crazy" Bob Lee also asked me how to solve a related problem in a dependency injection framework he is developing. The short answer is that you can't do it using type tokens
Further along in the entry, Neil offers the long answer which does solve the problem. However it much more complex than even he would like to have seen. Both the puzzle and the answer provide an very interesting insight into some of the complexities of Generics.