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
Like other answers, I am also hoping someone smarter can point out why the compiler isn't able to infer that T
is Boolean
.
One way to help out the compiler do the right thing, without requiring any changes to your existing class/interface design, is by explicitly declaring the formal parameter's type in your lambda expression. So, in this case, by explicitly declaring that the type of the value
parameter is Value
.
void test() {
Foo.foo((Value value) -> true).booleanValue();
}