Hello,
I am somewhat new to the Java Generics feature. Can you please help me to figure out why the code snippet below does not work:
interface Response {}
interface Request<T extends Response> {}
class TestResponse implements Response {}
class TestRequest implements Request<TestResponse> {}
<T extends Response> T foo(Request<T> b) {
TestResponse tr = new TestResponse();
return tr;
}
Everything seems good to me: the return value type implements the Response interface, however, the compiler disagrees: "Type mismatch: cannot convert from TestResponse to T"