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.
source
share