> No, there is no way to access the generic type, this information is lost
during the compilation process.
That's not actually correct. Lets consider the following class:
public class MyClass {
private List<Foo> foos;
public List<Bar> getBars() {
...
}
public void doStuffWithBaz() {
List<Baz> bazs = new ArrayList<Baz>();
...
}
}
In this example, the ONLY generic that will be lost after compilation (due
to type erasure) is Baz. Both Foo and Bar ARE available at runtime.
@see
http://docs.oracle.com/javase/7/docs/api/java/lang/reflect/Method.html#getGenericReturnType()
http://docs.oracle.com/javase/7/docs/api/java/lang/reflect/Field.html#getGenericType()