I would expect a good compiler to be able to detect an error, but as an optimization. You represent a specific case of a more general case:
public class TestCase {
public static TypeA methodA() {
return methodB();
}
public static <T extends TypeB> T methodB() {
return (T) null;
}
}
, , , :
- TypeA TypeB , TypeB TypeA.
- TypeA TypeA TypeB.
, , - №2, . , String - . , # 2 , .
, String CharSequence. , . , .
javac, , . , .
. : java.lang.String. : T.
, , , - :
public static CharSequence compiles() {
return (CharSequence)getAction();
}
.