+ 1
#what is lamda expression in java
In java
2 Respostas
+ 13
Lambda expressions are new features for JAVA, but it is already existing in Some other popular programming languages like Scala.
Java 8 onwards supports functional programming. Because now you can pass a function as a parameter in another function. It is an anonymous function(A function without a name). Java has been lacking this from the beginning. Let’s discuss it in detail.
Syntax of Lambda expression in Java8
(parameters) -> { statements; }
Round brackets (): It contains the parameters. The round brackets are mandatory.
Parameters: The parameter can be empty or non-empty as well. These parameters can use in the statement.
Arrow token ->: It is mandatory it’s just a symbol that links the parameters and statements.
Curly braces { }: These are not mandatory if you have one line of the statement.
Statements: You can place the statement or block of code.
For more details:https://javagoal.com/java-8-lambda-expressions/
+ 1
Lambda functions in java are a way of making anonymous functions in java.
Here's some information: https://www.w3schools.com/java/java_lambda.asp#:~:text=Lambda%20Expressions%20were%20added%20in,the%20body%20of%20a%20method.
An example is in java swing, I use lambda functions to simplify the actionPerformed method. Rather than making an anonymous class, I can just use a lambda function to save a bunch of extra, unnecessary lines of code:
JButton btn = new JButton("Click Me!");
btn.addActionListener(e -> System.out.println("Button was clicked"));
// ...