- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctionExample.java
More file actions
Latest commit
28 lines (17 loc) · 728 Bytes
/
Copy pathFunctionExample.java
File metadata and controls
28 lines (17 loc) · 728 Bytes
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
packagecom.learn.functionalInterfaces;
importjava.util.function.Function;
publicclassFunctionExample {
staticFunction<String, String> function1 = (str) -> str.toUpperCase();
staticFunction<String, String> function2 = (str) -> str.concat(" default");
publicstaticvoidmain(String[] args) {
System.out.println(performConcat("test"));
System.out.println(function1.andThen(function2).apply("test"));
/**
* Here function2 is performed first and it's result is passed to function1.
*/
System.out.println(function1.compose(function2).apply("test"));
}
publicstaticStringperformConcat(Stringstr) {
returnfunction2.apply(str);
}
}