2008-05-29

Erasure...

I suspect one of the predominant stumbling blocks in Java Generics will be the fact that you must always remind yourself "Oh, yeah, it only seems like we know something about the type parameter. That information has actually been erased." So here, you mean T[] array = new T[sz];, but erasure forgets about T so that's not legal. To solve the problem, you create an array of objects and cast it.
Stumbled on this while reviving two-year old code of mine, which was pretty 1.3-based. The code has not rotten all over and seems to be quite understandable. Let's do some generics to mess things up. ;)