File tree Expand file tree Collapse file tree 2 files changed +32
-0
lines changed
Modern-Java-Examples/src/com/learn Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -54,6 +54,10 @@ public List<String> getActivities() {
54
54
return activities ;
55
55
}
56
56
57
+ public void printActivities () {
58
+ System .out .println (activities );
59
+ }
60
+
57
61
public void setActivities (List <String > activities ) {
58
62
this .activities = activities ;
59
63
}
Original file line number Diff line number Diff line change
1
+ package com .learn .methodreference ;
2
+
3
+ import com .learn .data .Student ;
4
+ import com .learn .data .StudentDataBase ;
5
+
6
+ import java .util .function .Consumer ;
7
+
8
+ public class ConsumerMethodReferenceExample {
9
+
10
+ /**
11
+ * ClassName::methodName
12
+ */
13
+ static Consumer <Student > consumer = System .out ::println ;
14
+
15
+ /**
16
+ * ClassName::instanceMethodName
17
+ */
18
+ static Consumer <Student > consumer1 = Student ::printActivities ;
19
+
20
+ public static void main (String [] args ) {
21
+
22
+ StudentDataBase .getAllStudents ()
23
+ .forEach (consumer );
24
+
25
+ StudentDataBase .getAllStudents ()
26
+ .forEach (consumer1 );
27
+ }
28
+ }
You can’t perform that action at this time.
0 commit comments