I have a basic question regarding Java generics. I have a method that takes this as an argument:
public id findKey(List<String> ids, CustomClass clazz) {
repos.findID(ids, clazz);
}
I then want to use a java generic class as an argument for another method:
repos.findID(ids, clazz);
but my findID method needs a java generic class instead of clazz. How do I get my clazz argument from the findkey parameter and turn it to a generic class? If I do this:
public id findKey(List<String> ids, Class<T> clazz) {
repos.findID(ids, clazz);
}
I get an error because it won't recognize my T.
I'm at loss at how this stuff works and would appreciate any help.
Edit: Solved it. I can use ? or explicitly state a class type that I wanted and it accepted it.
Telsewhere in your method,Class<?>is sufficient. Otherwise, just define a type variable:public <T> id findKey(....