final Modifier
Description
You can use final
modifier in the parameter declaration for explicit lambda expressions.
The following lambda expressions use final modifier.
(final int x, final int y) -> { return x + y; }
We can just use one modifier as follows.
(int x, final int y) -> {return x + y;}
Example
public class Main {
public static void main(String[] argv) {
Processor stringProcessor = (final String str) -> str.length();
String name = "Java Lambda";
int length = stringProcessor.getStringLength(name);
System.out.println(length);//from w w w.j a va 2 s. c o m
}
}
@FunctionalInterface
interface Processor {
int getStringLength(String str);
}
The code above generates the following result.