-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctionAndLambda.java
More file actions
34 lines (27 loc) · 1.17 KB
/
Copy pathFunctionAndLambda.java
File metadata and controls
34 lines (27 loc) · 1.17 KB
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
29
30
31
32
33
package com.java8;
import java.util.Arrays;
import java.util.List;
import java.util.function.BiPredicate;
public class FunctionAndLambda {
public void toUpper(String greetings, FuncInterface funcInterface) {
System.out.println(funcInterface.helloSingleMethod(greetings));
}
public void testMethodReference() {
List<Integer> integerList = Arrays.asList(2,8,22,19,82);
BiPredicate<List<Integer>, Integer> isPartOf = List::contains;
BiPredicate<List<Integer>, Integer> isPartOfLambda = (List<Integer> list, Integer target) -> list.contains(target);
System.out.println(isPartOf.test(integerList, 8));
System.out.println(isPartOfLambda.test(integerList, 22));
}
public void testConstructorReference() {
EmployeeFactory employeeFactory = Employee::new;
Employee employee = employeeFactory.getEmployee("Jimmy", 37);
System.out.println(employee.age);
}
public static void main(String[] args) {
FunctionAndLambda fl = new FunctionAndLambda();
fl.toUpper("have a nice day", (str) -> str.toUpperCase());
fl.testMethodReference();
fl.testConstructorReference();
}
}