Differences between java type pins between javac 1.8.0_45 and javac 1.8.0_92?

I have code that compiles with javac 1.8.0_92:

public final class Either<L, R> {

    // ...

    private final L l;
    private final R r;

    // ...

    public <T> T join(final Function<L, T> f, final Function<R, T> g) {
        Preconditions.checkNotNull(f);
        Preconditions.checkNotNull(g);
        return which == LeftOrRight.LEFT ?
            f.apply(l) :
            g.apply(r);
    }

    public Optional<L> left() {
        return join(Optional::of, x -> Optional.empty());
    }

    // ...
}

However, javac 1.8.0_45some additional types ( L) are required :

     public Optional<L> left() {
         return join(Optional::<L>of, x -> Optional.<L>empty());
     }

As you can imagine, this causes problems for packages that the user creates from the source.

  • Why is this?

  • Is this a bug with a specific Java build?

+6
source share
1 answer

Yes, this is a JDK error where type inference fails with nested calls. If you set one of the arguments to null, compile the code.

https://bugs.openjdk.java.net/browse/JDK-8055963

Fixed for Java 9, but they also passed it to 8u60:

https://bugs.openjdk.java.net/browse/JDK-8081020

+5

All Articles