I am struggling a bit on assign-ability of generic type parameters.
Here are how my type definitions look:
public static interface CellValue<T> {
T getValue();
Class<?> getType();
}
public static class DoubleCell implements CellValue<Double> {
Double value;
public DoubleCell(Double value) {
super();
this.value = value;
}
@Override
public Double getValue() {
return value;
}
@Override
public Class<?> getType() {
return Double.class;
}
}
public static class FormulaCell implements CellValue<String> {
String value;
public FormulaCell(String value) {
this.value = value;
}
@Override
public String getValue() {
return value;
}
@Override
public Class<?> getType() {
return String.class;
}
}
Now, why do the following declarations work (to me, this is expected behaviour, but I may have misunderstood why it works)
Map<String, ? extends CellValue<?>> m = new HashMap<String, FormulaCell>();
Map<String, ? extends CellValue<?>> m2 = new HashMap<String, DoubleCell>();
..while the following do not?
Map<Integer, Map<String, ? extends CellValue<?>>> n = new HashMap<Integer, Map<String, FormulaCell>>();
Map<Integer, Map<String, ? extends CellValue<?>>> n2 = new HashMap<Integer, Map<String, DoubleCell>>();