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 ?

[1601 byte] By [stefan_bara] at [2007-11-26 19:20:05]
# 1
That's because List<Bar>.class doesn't exist. List.class exists, use that.
ejpa at 2007-7-9 21:37:45 > top of Java-index,Core,Core APIs...