river-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Benson Margulies <bimargul...@gmail.com>
Subject Re: Space/outrigger suggestions
Date Sun, 19 Dec 2010 22:09:57 GMT
I think, and I emphasize think, that I can help with this generic
question, but I apologize in advance if I've misunderstood.

Type erasure is real and irrevocable. Given an object of a generic
class, there is absolutely no way to recover the parameters.

If you want to carry the information around, you have to use
reflection to get hold of the classes that can describe a generic.
Tatu Saloranta's JSON libraries include some very clever type
descriptors that allow you to fairly easily get a reference to one of
these for an arbitrary type.

To avoid casts that get compile warnings, it's typical to have APIs like

   T getFoo(Class<T> clazz, whatever)

and

       return class.cast(returnValue);

This gives you return type checking and avoids the warnings.

The collections library intentionally avoids this and internally has
all those warnings to allow compatibility.

Mime
View raw message