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. ...