java easy to use lambda expressions code example
Example 1: how to use lambda in java
StateOwner stateOwner = new StateOwner();
stateOwner.addStateListener(
(oldState, newState) -> System.out.println("State changed")
);
Example 2: java "->"
interface LambdaFunction {
void call();
}
class FirstLambda {
public static void main(String []args) {
LambdaFunction lambdaFunction = () -> System.out.println("Hello world");
lambdaFunction.call();
}
}
Example 3: java "->"
Runnable r = ()-> System.out.print("Run method");
Runnable r = new Runnable() {
@Override
public void run() {
System.out.print("Run method");
}
};