How can I do something like this in Java 8?
boolean x = ((boolean p)->{return p;}).apply(true);
Right now I get the following error:
The target type of this expression must be a functional interface
How can I do something like this in Java 8?
boolean x = ((boolean p)->{return p;}).apply(true);
Right now I get the following error:
The target type of this expression must be a functional interface
As per the JLS section 15.27:
It is also possible to use a lambda expression in a
return
statement.We can then rewrite your example in four different ways:
By creating an assignment context:
By creating an invocation context:
By creating a casting context:
Using a
return
statement:Also, in this simple example, the whole lambda expression can be rewritten as: