The lambda expression example does not work in Java 8
•
Java
I'm trying to learn lambda expression in Java 8 I did install the Eclipse Plug-in and Java 8 SDK, but when I tried to execute the following code, eclipse showed an error
(String s) -> { s="hello"; System.out.println(s); }
It displays the error "the left side of the assignment must be a variable"
Please help.
Solution
Lambda expressions (and method references) are meaningful only in the context of an instance that requires a functional interface Otherwise, it will be impossible to determine whether the lambda is valid (and because you haven't done anything about it, it's useless)
It's like
Consumer<String> c = (String s) -> { s = "hello"; System.out.println(s); }; // as a Consumer,it doesn't really make sense for you to change s
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码