The interface method definition is:
Optional<? extends ABC<String, String>> getContextInfo();
The following method implementation compiles successfully in the implementation:
Optional<XYZ<String, String>> getContextInfo(){
...
}
Here XYZ is a subclass of ABC.
However, if the interface method uses a Map within Optional as follows:
Optional<Map<String,? extends ABC<String, String>>> getContextWithMap();
the following method implementation fails on compilation with the error: Attempting to use incompatible return type
Optional<Map<String, XYZ<String, String>>> getContextWithMap(){
...
}
I use java 8 and haven't tested this on higher versions. Why does compilation flag an incompatible return type error in this case? How can this be fixed?