arguments - Lambda expression gives "invalid tokens" syntax error in Java -


i started learn lambda expression , did this:

public class lambdatest {      public static void main(string[] args) {         int num = returnnumber((num) -> { return 4 });     }      public static int returnnumber(int num) {         return num;     } } 

but gives me error: "invalid tokens". here image:

can please explain me what's wrong? it's test.

i have java 1.8 supported in eclipse installation (luna 4.4).

there few restrictions on can done in body of lambda, of pretty intuitive—a lambda body can’t “break” or “continue” out of lambda, , if lambda returns value, every code path must return value or throw exception, , on. these same rules standard java method, shouldn’t surprising.

reference : http://www.oracle.com/technetwork/articles/java/architect-lambdas-part1-2080972.html

the method's body has effect of evaluating lambda body, if expression, or of executing lambda body, if block; if result expected, returned method.

if function type's result void, lambda body either statement expression or void-compatible block.

reference : http://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.27.4


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -