Possible regression involving inferred generic types

Mark Derricutt mark at talios.com
Wed Oct 16 16:30:13 PDT 2013


Interesting, this sounds similar to issue I came across the other week relating to covariant returns in relation to generics.

So far I've narrowed it down to issues with using mixing raw types and generics. Alas I've yet to get a simple test case working, other than my small maven project which shows the problem I encountered [1].

The problem I had stemmed from a class being defined as Condition<T>, but one of my implementations of that class simply "implements Condition" without mentioning anything for T. JDK7's javac happily works with this, but JDK8 seems to encounter issues, but only in the place where multiple invocations of an instance of this type was involved.

You're examples here look to be more useful as they're WAY simpler and concrete things, assuming the two are related.

Mark


[1] https://github.com/talios/jdk8-covariantfail


On 17 Oct 2013, at 12:08, 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.
>
> -------------------------------------------------------------------------------
> 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 495 bytes
Desc: OpenPGP digital signature
Url : http://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20131017/774e031e/signature.asc 


More information about the compiler-dev mailing list