Since g is a generic method, Java indicates the type g to match the return type f.
You can see this by doing the following three functions.
class SomeClass{
<T> T g(){return null;}
String f() {
return this.<String>g();
}
Integer h() {
return this.<Integer>g();
}
Integer i() {
return this.<String>g();
}
}
f and h will compile fine because it infers the type from the return type. I will not compile because the types do not match.
source
share