Skip to content

Commit a3fe1f3

Browse files
author
Elsa Hill
committed
Further exercises
1 parent 3ae747d commit a3fe1f3

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

2.1-exercise/src/LambdaFun.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+

2.1-exercise/src/PrettyApple.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ a String output from an apple (a bit like multiple customized
1212

1313
public 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) {

0 commit comments

Comments
 (0)