-
Bug
-
Resolution: Not an Issue
-
P4
-
None
-
7
-
generic
-
generic
Certain method invocations involving type inference pass the compiler, even though the equivalent without inference is clearly illegal. Key elements seem to be a wildcard with an interface lower bound and an assignment to a target type.
interface A { boolean isBlue(); }
<T> T makeT(Iterable<? super T> l) { return null; }
String makeStr(Iterable<? super String> l) { return null; }
{
Iterable<? super A> la = null;
Iterable<? super Number> ln = null;
Iterable<? super Cloneable> lc = null;
String s1 = makeT(la); // no error!
String s2 = makeT(ln); // error
String s3 = makeT(lc); // no error!
String s4 = makeStr(la); // error
String s5 = makeStr(ln); // error
String s6 = makeStr(lc); // error
}
interface A { boolean isBlue(); }
<T> T makeT(Iterable<? super T> l) { return null; }
String makeStr(Iterable<? super String> l) { return null; }
{
Iterable<? super A> la = null;
Iterable<? super Number> ln = null;
Iterable<? super Cloneable> lc = null;
String s1 = makeT(la); // no error!
String s2 = makeT(ln); // error
String s3 = makeT(lc); // no error!
String s4 = makeStr(la); // error
String s5 = makeStr(ln); // error
String s6 = makeStr(lc); // error
}