How to use .class with generics
Okay, in Java 5, Foo.class works just fine. But Map<Foo,Bar>.class does not. What is the right format?
I am trying to get a field value through reflection:
publicstatic <T> T readFieldValueCastSave(
Object target,
String fieldName,
Class<T> fieldType)
throws Exception{
T r =null;
Field f = getField(target.getClass(), fieldName);
f.setAccessible(true);
r = fieldType.cast(f.get(target));
f.setAccessible(false);
return r;
}
So this method works just fine for something like this:
class Foo{
private Bar myBarField;
}
Bar b = readFieldValueCastSave(myFooObj,"myBarField", Bar.class);
Now, what do I do in this case:
class Foo{
private List<Bar> myList;
}
List<Bar> l = readFieldValueCastSave(myFooObj,"myList", List<Bar>.class);
List<Bar>.class simply does not compile.
Any suggestions ?

