java - Passing a concrete List of EnumMap objects to generic List of EnumMap parameter causes compile error -
I have a piece of code that I think should be compiled, but it is not. Public Code Program {Public Zero My Mathew (List & lt; EnumMap & lt ;, MyInterface, String & gt; & gt; Maps) {} Public Zero Collar () {EnumMap & lt; MyEnum, String & gt; ; Map = new enamel map & lt; MyName, String & gt; (Myanm. Class); List & lt; EnumMap & lt; MyEnum, String & gt; & Gt; List = new linked list & lt; EnumMap & lt; MyEnum, String & gt; & Gt; (); MyMethod (list); // error logic type is not compatible}
}
MyName is an eMan that implements the MyEnfaces
Why does myMethod (list) call me logic type not compatible?
If I change the signature of my Mathi in the following:
Public Zero expand my Math (List & lt;? Map, Mieantface, String & gt; ; & Gt; spreads the map)
Then everything works fine, but I am still surprised and want to know why the basic method signature does not work.
enummark & lt; MyEnum, String & gt;
and EnumMap & lt;? MyInterface, string & gt;
is spread, there are different types (pre-posterior subtypes) then list & lt; EnumMap & lt; MyEnum, String & gt; & Gt;
and list & lt; EnumMap & lt;? Extends MyInterface, string & gt; & Gt;
are not compatible with each other. Normally, there is nothing in the relationship between A and B, if any A and B are different, then list & lt; A & gt;
List & lt; B & gt;
can not be assigned to list not only for any common type). When you have a bound type parameter, then this is a different story; Compatibility takes into account the limit.
Comments
Post a Comment