After trying to identify the problem with my generic method, I've ended up with the following code:
Map<String, BiConsumerThatThrows<CheckPayment, XMLEventReader>> a = CheckPayment.childMapper;
BiConsumerThatThrows<CheckPayment, XMLEventReader> a1 = a.get("1");
BiConsumerThatThrows<? super CheckPayment, XMLEventReader> b1 = a1;
Map<String, BiConsumerThatThrows<? super CheckPayment, XMLEventReader>> b = new HashMap<>();
b.put("1", b1);
b = a;
It won't compile with the following error (I've formatted it to make it more readable):
[ERROR] /D:/lalala/MyClass.java:[152,27]
incompatible types:
java.util.Map<
java.lang.String,
blablabla.BiConsumerThatThrows<
blablabla.CheckPayment,
javax.xml.stream.XMLEventReader
>
>
cannot be converted to
java.util.Map<
java.lang.String,
blablabla.BiConsumerThatThrows<
? super blablabla.CheckPayment,
javax.xml.stream.XMLEventReader
>
>
What's most surprising, it crashes only on the last line of the given code snippet.
Why does it happen? What can be done to perform such assignment?
I'm using Oracle JDK 1.8u40 x64.
P.S. Here is the simplified example:
Set<Set<String>> sets = new HashSet<>();
Set<Set<? super String>> sets2 = new HashSet<>();
sets2 = sets;
Error:
incompatible types: java.util.Set<java.util.Set<java.lang.String>> cannot be converted to java.util.Set<java.util.Set<? super java.lang.String>>
P.P.S. Even this is not working:
Set<Set<Object>> sets2 = new HashSet<Set<String>>();
why?