66import java .util .ArrayList ;
77import java .util .Arrays ;
88import java .util .List ;
9+ import java .util .function .Consumer ;
910
11+ @ FunctionalInterface
1012interface Criterion <E > {
1113 boolean test (E s );
14+ // void doStuff();
1215}
16+ //
17+ //interface Something<E> {
18+ // void doSomething(E e);
19+ //}
1320
14- interface Something <E > {
15- void doSomething (E e );
16- }
17-
18- class PrintSomething implements Something <Student > {
21+ //class PrintSomething implements Something<Student> {
22+ class PrintSomething implements Consumer <Student > {
1923 @ Override
20- public void doSomething (Student student ) {
24+ // public void doSomething(Student student) {
25+ public void accept (Student student ) {
2126 System .out .println ("> " + student );
2227 }
2328}
@@ -29,9 +34,11 @@ public class School {
2934// }
3035// System.out.println("---------------------------");
3136// }
32- public static <E > void withEvery (Iterable <E > ls , Something <E > someObject ) {
37+ // public static <E> void withEvery(Iterable<E> ls, Something<E> someObject) {
38+ public static <E > void withEvery (Iterable <E > ls , Consumer <E > someObject ) {
3339 for (E s : ls ) {
34- someObject .doSomething (s );
40+ // someObject.doSomething(s);
41+ someObject .accept (s );
3542 }
3643 }
3744
@@ -58,7 +65,7 @@ public static void main(String[] args) {
5865// });
5966
6067 // show smart students
61- // showAll (getByCriterion(roster, ??? ));
68+ withEvery (getByCriterion (roster , s -> s . getGpa () > 3.0 ), s -> System . out . println ( s ));
6269
6370 // show unenthusiastic students
6471// showAll(getByCriterion(roster, ???));
0 commit comments