Loading src/main/java/ch10c/HelloLambda.java +13 −0 Changes for src/main/java/ch10c/HelloLambda.java: 13 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -2,6 +2,8 @@ package ch10c; import java.util.ArrayList; import java.util.List; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.function.Consumer; import java.util.function.Function; import java.util.stream.Collectors; Loading Loading @@ -61,6 +63,12 @@ public class HelloLambda { System.out.println("result = " + result); } static void compare() { List<String> strings = new ArrayList<>(List.of("I", "am", "a", "list", "of", "Strings")); Stream<String> sorted = strings.stream().sorted( (str1, str2) -> str1.compareToIgnoreCase(str2)); } static void noReturn() { List<String> strings = new ArrayList<>(List.of("I", "am", "a", "list", "of", "Strings")); strings.forEach( Loading @@ -71,6 +79,11 @@ public class HelloLambda { ); } static void noArgs() { ExecutorService executorService = Executors.newFixedThreadPool(1); executorService.submit(() -> System.out.println("Hello!")); } static void mandatoryTypes() { // if you remove String from the param here, the compiler doesn't know which method you want overloadedMethod((String str) -> System.out.println(str)); Loading Loading
src/main/java/ch10c/HelloLambda.java +13 −0 Changes for src/main/java/ch10c/HelloLambda.java: 13 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -2,6 +2,8 @@ package ch10c; import java.util.ArrayList; import java.util.List; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.function.Consumer; import java.util.function.Function; import java.util.stream.Collectors; Loading Loading @@ -61,6 +63,12 @@ public class HelloLambda { System.out.println("result = " + result); } static void compare() { List<String> strings = new ArrayList<>(List.of("I", "am", "a", "list", "of", "Strings")); Stream<String> sorted = strings.stream().sorted( (str1, str2) -> str1.compareToIgnoreCase(str2)); } static void noReturn() { List<String> strings = new ArrayList<>(List.of("I", "am", "a", "list", "of", "Strings")); strings.forEach( Loading @@ -71,6 +79,11 @@ public class HelloLambda { ); } static void noArgs() { ExecutorService executorService = Executors.newFixedThreadPool(1); executorService.submit(() -> System.out.println("Hello!")); } static void mandatoryTypes() { // if you remove String from the param here, the compiler doesn't know which method you want overloadedMethod((String str) -> System.out.println(str)); Loading