It's possible to chain/concatenate what is done with elements in a lambda expression like this:
list.forEach(s -> {
System.out.println(s.toLowerCase());
System.out.println(s.toUpperCase());
});
Is there a way to do this also with method references? Something like this:
list.forEach({
System.out::println(String::toLowerCase);
System.out::println(String::toCase);
});
I know I could do this in four separate calls (which do also more, that is mutate the values):
list.replaceAll(String::toLowerCase);
list.forEach(System.out::println);
list.replaceAll(String::toUpperCase);
list.forEach(System.out::println);
I can't even do something easy like this:
list.forEach({
System.out::println;
System.out::println;
});
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…