When I try to compile the following code, compilation fails with the following error. I'm not sure why it should as I am only returning a class that implements the contract
public interface Contract {
static <T extends Contract> T get() {
return new ConcreteContract();
}
}
class ConcreteContract implements Contract {
}
Contract.java:3: error: incompatible types: ConcreteContract cannot be converted to T
return new ConcreteContract();
^
where T is a type-variable:
T extends Contract declared in method <T>get()
1 error
Does anyone have a clue why java behaves this way (or) am I missing something obvious
PS: I have read more than 10 top searches in SO before posting this query