28
28
* a,d -> d.quack() ==> (a, d) -> d.quack()
29
29
* Animal a, Duck d -> d.quack() ==> (Animal a, Duck d) -> d.quack()
30
30
*
31
- * a, b - a.startsWith("a") ==> (a, b) -> a.startsWith("a")
31
+ * a, b -> a.startsWith("a") ==> (a, b) -> a.startsWith("a")
32
32
*
33
33
* (when one parameter has a data type listed, though,
34
34
* all parameters must provide a data type)
@@ -48,7 +48,6 @@ public Animal(String species, boolean canHop, boolean canSwim) {
48
48
}
49
49
50
50
public Animal (String species2 , int age , List <String > favoriteFoods ) {
51
- // TODO Auto-generated constructor stub
52
51
}
53
52
54
53
public boolean canHop () {
@@ -64,19 +63,18 @@ public String toString() {
64
63
}
65
64
}
66
65
66
+ @ FunctionalInterface
67
67
interface CheckTrait {
68
68
public boolean test (Animal a );
69
69
}
70
70
71
71
public class ImplementingFunctionalInterfacesWithLambdas {
72
-
73
72
private static void print (Animal animal , Predicate <Animal > trait ) {
74
73
if (trait .test (animal ))
75
74
System .out .println (animal );
76
75
}
77
76
78
77
public static void main (String [] args ) {
79
-
80
78
// Java relies on context when figuring out what lambda expressions mean
81
79
// a -> a.canHop() ==> (Animal a) -> {return a.canHop();}
82
80
print (new Animal ("fish" , false , true ), a -> a .canHop ());
0 commit comments