I’ve got the following method of an public abstract class Model { //impl } (declared exactly like this):
protected <T extends Model> HashMap<String, Model> resultsetMap(ResultSet res) {
HashMap<String, Model> data = new HashMap<String, Model>();
try {
while(res.next()) {
Model obj = T.getNew(res);
data.put(obj.toString(), obj);
}
} catch(SQLException e) {
return null;
}
return data;
}
Tis supposed to tell the caller the concrete class it should use. Is this possible?- How would I call this method from another method of a subclass of
Model? I’ve tried withresultsetMap<Course>(res);but it looks like a syntactic error
Since the method is inherited, you can call it either as
super.<ConcModel>resultsetMap(/* arg */);orthis.<ConcModel>resultsetMap(/* arg */);. Second or first respectively based on whether the subclass is overriding it or not.Tutorial on how to call a generic method.