The answer comes down to Java does not support lower bounds on parameterized methods, because such a feature is "not useful enough" , see a similar question
Given the following snippet:
package demo; public class Demo { interface Foo { void foo(); } interface Bar { void bar(); } interface FooBar { <R extends Foo & Bar> R foobar(); static FooBar create() { return new TypicalJavaFooBar(); } } private static final class TypicalJavaFooBar implements Foo, Bar, FooBar { public void bar() { System.out.println("foo"); } public void foo() { System.out.println("bar"); } public <R extends Foo & Bar> R foobar() { return (R) this; } } public static void main(String[] args) { FooBar x = FooBar.create(); Foo foo = x.foobar(); Bar bar = x.foobar(); x.foobar().foo(); x.foobar().bar(); } }
Without explicit cast to R in TypicalJavaFooBar#foobar compiler fails with the following error
Error: (13, 20) java: incompatible types: demo.Demo.TypicalJavaFooBar could not be converted to R
My question is why? It seems to me that the compiler should have enough information, since TypicalJavaFooBar is clearly defined to implement both Foo and Bar ; why is this not enough to satisfy the Foo & Bar restriction?
UPDATE
The main goal of this exercise is to define the following contract: the method of calling foobar on the foobar instance is guaranteed to return something that implements both Foo and Bar .
source share