Skip to content

Commit ea0624f

Browse files
committed
add chapter10
1 parent 332f6da commit ea0624f

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ This repository contains the code examples from the book [Modern Java in Action]
1515
- Chapter 7. Parallel data processing and performance | [java](https://github.com/codejsha/modern-java-in-action/tree/main/src/main/java/com/example/demo/chapter07)([test](https://github.com/codejsha/modern-java-in-action/tree/main/src/main/test/com/example/demo/chapter07))
1616
- Chapter 8. Collection API enhancements | [java](https://github.com/codejsha/modern-java-in-action/tree/main/src/main/java/com/example/demo/chapter08)([test](https://github.com/codejsha/modern-java-in-action/tree/main/src/main/test/com/example/demo/chapter08))
1717
- Chapter 9. Refactoring, testing, and debugging | [java](https://github.com/codejsha/modern-java-in-action/tree/main/src/main/java/com/example/demo/chapter09)([test](https://github.com/codejsha/modern-java-in-action/tree/main/src/main/test/com/example/demo/chapter09))
18+
- Chapter 10. Domain-specific languages using lambdas | [java](https://github.com/codejsha/modern-java-in-action/tree/main/src/main/java/com/example/demo/chapter10)([test](https://github.com/codejsha/modern-java-in-action/tree/main/src/main/test/com/example/demo/chapter10))
1819

1920
(work in progress)
2021

21-
- Chapter 10. Domain-specific languages using lambdas
2222
- Chapter 11. Using Optional as a better alternative to null
2323
- Chapter 12. New Date and Time API
2424
- Chapter 13. Default methods
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.example.demo.chapter10;
2+
3+
import lombok.extern.slf4j.Slf4j;
4+
5+
import java.util.List;
6+
import java.util.function.Consumer;
7+
8+
@Slf4j
9+
public class PrintNumber {
10+
public static void printNumbersByAnonymousClass(List<String> numbers) {
11+
numbers.forEach(new Consumer<String>() {
12+
@Override
13+
public void accept(String number) {
14+
log.info("{}", number);
15+
}
16+
});
17+
}
18+
19+
public static void printNumbersByLambda(List<String> numbers) {
20+
numbers.forEach(number -> log.info("{}", number));
21+
}
22+
23+
public static void printNumbersByMethodReference(List<String> numbers) {
24+
numbers.forEach(System.out::println);
25+
}
26+
}

0 commit comments

Comments
 (0)