Possible regression involving inferred generic types
cushon
cushon at google.com
Wed Oct 16 17:48:43 PDT 2013
Forwarded from compiler-dev at Alex Buckley's suggestion. Original thread:
http://mail.openjdk.java.net/pipermail/compiler-dev/2013-October/007726.html
I found some cases where javac 8 behaviour diverges from javac 7, and I'm
interested in knowing whether this is a bug or an intentional change.
The following programs do not compile with the jdk8 javac. (I tried b111 and
954dd199d6ff). All of the programs compile with the jdk7 javac.
-------------------------------------------------------------------------------
import java.util.List;
class ReproOne {
static class Baz<T> {
public static List<Baz<Object>> getElements(Baz<Object> transcoder) {
return null;
}
}
private static void bar(Baz arg) {
for (Baz element : Baz.getElements(arg)) {}
}
}
-------------------------------------------------------------------------------
abstract class ReproTwo<T> {
class Bar<E> {}
T get(Bar<? extends T> arg1, Bar arg2) {
return circularGet(arg2, arg2);
}
abstract T circularGet(final Bar<? extends T> arg1, final Bar<?> arg2);
}
-------------------------------------------------------------------------------
abstract class ReproThree<T, V> {
class Binding<E> {}
class ProviderBinding<E> extends Binding<E> {}
abstract V visitOther(Binding<? extends T> binding);
public V visitTwo(ProviderBinding<? extends T> providerBinding) {
return visitOther((Binding) providerBinding);
}
}
-------------------------------------------------------------------------------
javac output:
ReproOne.java:12: error: incompatible types: Object cannot be converted to
Baz
for (Baz element : Baz.getElements(arg)) {}
^
ReproTwo.java:6: error: incompatible types: Object cannot be converted to T
return circularGet(arg2, arg2);
^
where T is a type-variable:
T extends Object declared in class ReproTwo
ReproThree.java:10: error: incompatible types: Object cannot be converted
to V
return visitOther((Binding) providerBinding);
^
where V is a type-variable:
V extends Object declared in class ReproThree
More information about the lambda-dev
mailing list