Possible regression involving inferred generic types
Remi Forax
forax at univ-mlv.fr
Wed Oct 16 16:27:25 PDT 2013
On 10/17/2013 01:08 AM, Liam Miller-Cushon wrote:
> Hi all,
>
> The following programs do not compile with the jdk8 javac. (I tried
> b111 and
> 954dd199d6ff). All of the programs compile with the jdk7 javac.
Hi Liam,
it's not clear for me, if you know why it doesn't compile.
So let me first explain, why all your snippets doesn't compile.
They all suffer the same issue, at some point the code use a raw type
and javac8 doesn't do inference in that case. javac7 is more flexible
about that.
I think this bug was already submitted to the core-dev mailing list not
a long time ago
(last week or the week before, I think).
Anyway, I don't know if it's a regression or if it's a try to move to a
more safer world
with no raw type in the middle of programs*.
cheers,
Rémi
* the JLS also introduces raw types when typecheking A.class or
foo.getClass() so
get ride of *all* raw types is not practical.
>
> -------------------------------------------------------------------------------
> 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 compiler-dev
mailing list