I have the following classes:
abstract class DTO{ }
class SubscriptionDTO extends DTO { }
and the following generic method:
protected void fillList(ResultSet rs, ArrayList<? extends DTO> l)
throws BusinessLayerException {
SubscriptionDTO bs;
try {
while (rs.next()){
//initialize bs object...
l.add(bs); //compiler error here
}
} catch (SQLException e) {
e.printStackTrace();
}
}
I can't seem to understand why you can't create a generic method for filling DTO subtypes. Am I doing something wrong or is this by design? If so, is there any workaround? Thanks in advance.