forked from michaelangelo2288/Functional-Interface
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConsumerTest.java
More file actions
39 lines (31 loc) · 1.08 KB
/
Copy pathConsumerTest.java
File metadata and controls
39 lines (31 loc) · 1.08 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
34
35
36
37
38
39
import org.junit.Test;
import java.util.function.Consumer;
// *** The point of lambda expression relating to functional interface is the lambda EXPRESSION
// is defining the single method accept() method for Consumer<T>, inside the functional
// interface
public class ConsumerTest {
@FunctionalInterface
interface TestInterface {
public void someMethod();
}
// Using custom functional interface TestInterface
@Test
public void consumerTestMethod1() {
// lambda expression defines what TestInterface functional interface's someMethod() does
TestInterface tI;
tI = () -> {
System.out.println("hi");
};
tI.someMethod();
}
// Using built-in functional interface Consumer<T>
@Test
public void consumerTestMethod2() {
// lambda expression defines what Consumer<T> functional interface's accept() does
Consumer<String> consumer;
consumer = a -> {
System.out.println(a);
};
consumer.accept("this will be printed per lambda expression defined");
}
}