Suppose I have a List definition as follows.
private List<? extends GeneralBudgetYearBean> budgetYearBeans;
// + Getters/setters...
Why am I unable to generally refer to this List as follows outside this class:
GeneralBudgetYearBean gbyb;
getBudgetYearBeans().add(bgyb);
The error is:
The method add(capture#6-of ? extends GeneralBudgetYearBean) in the type List<capture#6-of ? extends GeneralBudgetYearBean> is not applicable for the arguments (GeneralBudgetYearBean)
This doesn't make sense. Is it because "? extends T" is not the same as "T", and "T" can't be substituted here?
I need to be able to generally manipulate this class without specifics. At some point, there will be an ArrayList of "SUBGeneralBudgetYearBeans" constructed in extending classes, which is why I need to use the "? extends GeneralBudgetYearBean" notation.