Typically, I\'ve seen people use the class literal like this:
Class cls = Foo.class;
But what if the type is generic, e.g. List?
Due to the exposed fact that Class literals doesn't have generic type information, I think you should assume that it will be impossible to get rid of all the warnings. In a way, using Class
is the same as using a collection without specifying the generic type. The best I could come out with was:
private > List getList(Class cls) {
List res = new ArrayList();
// "snip"... some stuff happening in here, using cls
return res;
}
public > List> getList() {
return getList(A.class);
}