File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change 1+ package lambdasinaction .lambda ;
2+
3+ import lambdasinaction .appd .Lambda ;
4+ import lambdasinaction .chap3 .Lambdas ;
5+ import lambdasinaction .chap3 .Lambdas .*;
6+
7+ import java .util .Comparator ;
8+
9+ public class LambdaFun {
10+ // To try: https://javabrains.io/courses/java_lambdabasics/lessons/Lambda-Exercise/
11+ public static void main (String [] args ) {
12+
13+ // Must return an object with a Functional Interface
14+ Runnable o = () -> System .out .println ("Trixy" );
15+
16+ // Can use type inference or be explicit and provide the object type in the parameter.
17+ Comparator <Lambdas .Apple > c = (Apple a1 , Apple a2 ) -> a1 .getWeight ().compareTo (a2 .getWeight ());
18+ Comparator <Lambdas .Apple > c2 = (a1 , a2 ) -> a1 .getWeight ().compareTo (a2 .getWeight ());
19+ }
20+ }
21+
Original file line number Diff line number Diff line change @@ -12,7 +12,6 @@ a String output from an apple (a bit like multiple customized
1212
1313public class PrettyApple implements ApplePredicate {
1414
15-
1615 public static void prettyPrintApple (List <Apple > inventory , ApplePredicate applePredicate ) {
1716 List <Apple > greenHeavyAppleList = new ArrayList <>();
1817 for (Apple apple : inventory ) {
You can’t perform that action at this time.
0 commit comments