I have a class which objects are constructed with a map of strings and maps of string and a generic type that extends Number, like this:
public MyClass(Map<String,HashMap<String,? extends Number>){ ... }
I also have another class that extends number:
public Class MySecondClass extends Number { ... }
In an external method i create a map made of string and maps of strings and MySecondClass objects
public void myMethod() {
...
Map<String, HashMap<String, MySecondClass> foo = ...;
...
}
And it looks like i could call the constructor of MyClass
using the foo map without any problem, because MySecondClass
extends Number, but i get keep getting and error that says:
MyClass(java.util.Map<java.lang.String, java.util.HashMap<java.lang.String, ? extends java.lang.Number>>) in MyClass cannot be applied
to (java.util.Map<java.lang.String, java.util.HashMap<java.lang.String, MySecondClass>>)
and i can't understand why.. i also have other methods which calls the same constructor using similar maps but instead of using MySecondClass
they use Long or Integer that obviously extends Number and there should not be difference between those classes because they all extend Number.. what did i do wrong?
I am using java 10