Type inference problem with JDK 8 Build 82

Gernot Neppert mcnepp02 at googlemail.com
Wed Apr 3 07:39:04 PDT 2013


Hi,

here's some feedback regarding source compatibility of the Java 8 compiler.
First of all, Kudos to you compiler guys!
In a codebase of appr. 800 classes that have been used previously with Java
7, only one compilation problem showed up when I test-fed the source to
javac 8 Build 82.
Considering the heavy changes that have been implemented, I'm impressed
that compatibility remains that high!

Here's a condensed version of the source that causes the problem:

interface Expression<S,T> {
    <U> Expression<S,? extends U> cast(Class<U> target);
}

class BatchExpression<S,T> implements Expression<S,T> {
    private BatchExpression(Expression<? super S, ?> first,
            Expression<? super S, T> second) {
        super();
        this.first = first;
        this.second = second;
    }

    private final Expression<? super S, ?> first;
    private final Expression<? super S, T> second;

    public static <S,T> BatchExpression<S,T> create(Expression<? super S,?>
first, Expression<? super S, T> second) {
        return new BatchExpression<S, T>(first, second);
    }

    @Override
    public <U> Expression<S, ? extends U> cast(Class<U> target) {
// This is where the compiler chokes:
        return create(first, second.cast(target));
    }
}


More information about the lambda-dev mailing list