Generics Do's and Dont's

I have posted our slides from our JavaOne Session
BOF-9225 "Generic Do's and Don'ts" on my blog:
http://blogs.sun.com/roller/page/ahe?entry=impressions_from_javaone
I got a lot of inspiration from this forum, so thank you all!
I hope to elaborate more on this in the future, perhaps
with blog entries or an article on java.net. If you have more
ideas which fit in the category of "generic do's and don'ts",
please let me know.

Nice summary Peter. Couple of things you could fix if you get a chance to do another version:
On slide 18, you don't use the second argument to the constructor 't':
final class CheckedBox<T> {
    final Class<T> type;
    T t;
    CheckedBox(Class<T> type, T t) {
    this.type = type;
...On slide 20, I think you've forgotten to actually pass the Type Token to the constructor of the CheckedBox!
CheckedBox<String> bs = new CheckedBox<String>();   //??
CheckedBox rawBox = bs;
rawBox.setValue(3); // ClassCastException
String s = bs.getValue(); // never gets hereOr did I missunderstand something?

Similar Messages

Maybe you are looking for