I'm surprised, why did the lambda expression can't be invoked at runtime correctly. is it a type inference error? The work aournd example is uncomment the explicit type argument declaration.
public class LambdaConversionTest {
@Test
public void whyDidLambdaExpressionFailsWithLambdaConversionException() {
try {
// v--- when uncomment it, the behavior is what I expected
Stream./*<Collector>*/of(new Robot(), new Puller())
.flatMapToInt(Collector::stream).sum();
fail("fails with expected behavior");
} catch (BootstrapMethodError why) {
assertThat(why.getCause().getMessage()
,containsString("Invalid receiver type interface "));
}
}
interface Marker {
}
interface Collector {
IntStream stream();
}
class Robot implements Collector, Marker {
@Override
public IntStream stream() {
return IntStream.empty();
}
}
class Puller implements Collector, Marker {
@Override
public IntStream stream() {
return IntStream.empty();
}
}
}