A Lambda expression (or function) is just an anonymous function,
i.e., a function with no name and without being bounded to an
identifier. They are written exactly in the place where it’s needed,
typically as a parameter to some other function.
Syntax:
Example:
package lambda;
public class Two {
public static void main(String args[]) {
new Thread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
System.out.println("hello runnable");
}
}).start();
new Thread(()-> System.out.println("hello lambda runnable")).start();
}
}
Ref: https://howtodoinjava.com/java-8-tutorial/
Syntax:
either
(parameters) -> expression
or
(parameters) -> { statements; }
or
() -> expression
Example:
package lambda;
public class Two {
public static void main(String args[]) {
new Thread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
System.out.println("hello runnable");
}
}).start();
new Thread(()-> System.out.println("hello lambda runnable")).start();
}
}
Ref: https://howtodoinjava.com/java-8-tutorial/
No comments:
Post a Comment