A method with this signature constructs an object of class objClass which is somewhere in the BaseModel hierarchy, and adds it to the list with ? extends BaseModel objects.
public void constructAndAdd(List<? extends BaseModel> list, Class objClass)
{
BaseModel newObject = (BaseModel)objClass.newInstance();
list.add(newObject);
}
Error:
The method add(capture#2-of ? extends BaseModel) in the type List<capture#2-of ? extends BaseModel> is not applicable for the arguments (BaseModel)
I wish I could do
? extends BaseModel newObject = (? extends BaseModel)objClass.newInstance();
but that syntax is wrong.
Twill be that derived class.