I'd expect the following to compile:
given the generic method
<T> T getOption();
the subsequent call will fail to compile with javac
int i = getOption();
At first I regarded this as a javac bug, but after a deeper look at the spec, it seems that no autoboxing should be exploited here:
accordingly to 15.12.2.8, a constraint of the kind int >> T should be derived. However it seems that rules in 15.12.2.7 cannot derive the constraint Integer >> T starting from this initial constraint. So we cannot derive anything useful from this constraint. Maybe 15.12.2.8 should be changed in order replaced the primitive type with the boxed type in case the return type is primitive.
Here's a test-case:
public class X {
public static <T> T getValue(T t1, T t2) {
return t1;
}
public void testGenerics(Comparable<String> s) {
int i = getValue(0, s);
}
}