Consider the following example,
class ClsA {}
class ClsB {}
interface IntA {}
interface IntB {}
And I have 2 very similar methods:
static <T extends ClsA> T returnC() { // Here T extends the class
return null;
}
static <T extends IntA> T returnI() { // Here T extends the interface
return null;
}
And then the method calls:
ClsA ac = returnC(); // This works fine based on inference.
IntA ai = returnI(); // Similarly this works fine based on inference.
But consider the below 2:
ClsB bc = returnC(); // ERROR as expected.
Eclipse Error:
Bound mismatch: The generic method returnC() of type Testing is not applicable for the arguments (). The inferred type ClsB&ClsA is not a valid substitute for the bounded parameter
<T extends ClsA>
But the following code compiles fine:
IntB bi = returnI(); // Works fine
Why is that for interface, the generics bound is not considered in return types?