I have a weird scenario where type inference isn\'t working as I\'d expect when using a lambda expression. Here\'s an approximation of my real scenario:
stat
I don't know why but you need to add separate return type:
public class HelloWorld{
static class Value {
}
@FunctionalInterface
interface Bar {
R apply(Value value); // Return type added
}
static class Foo {
public static R foo(Bar callback) {
return callback.apply(new Value());
}
}
void test() {
System.out.println( Foo.foo(value -> true).booleanValue() ); // No compile error here
}
public static void main(String []args){
new HelloWorld().test();
}
}
some smart guy probably can explain that.