I have a class named “toto” which I send to a function that does the following:
getData(toto);
public String getData(Class myClass) {
javax.jdo.Query query = p.newQuery(myClass);
List<myClass> list = (List<myClass>) pm.newQuery(query).execute();
for (myClass element : list) {
Do something here
}
}
The problem is that I get type compilation error.
What am I doing wrong?
Joel
You can’t use a runtime variable as an “argument” to a generics construct (like
List<X>). If you know something about the classes you’ll pass in, then you can constrain that: