JAVA
java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/*
* Use a lambda expression as an argument
* to a method.
*/
interface StringFunc{
String func(String str);
}
class LambdaArgumentDemo{
/*
* This method has a functional interface
* as the type of its first parameter.
* Thus, it can be passed a reference
* to any instance of that interface,
* incuding an instance created by a
* lambda expression. The second parameter
* specifies the string to operate on.
*/
static String changeStr(StringFunc sf, String s){
return sf.func(s);
}
public static void main(String[] args){
System.out.println(
"*** Lambda Argument Demo ***\n");
String inStr = "Break Your Limits";
String outStr;
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run