English
Summary
Conclusions
A lambda expression implements a functional interface, and its type is determined by the target context. The standard java.util.function interfaces describe common forms of behavior, their composition builds new conditions and transformations, and method references and Comparator.comparing concisely express delegation and ordering. Optional explicitly marks the absence of a result but does not replace an empty collection or a domain error. A stream connects a source, lazy intermediate operations, and a terminal operation, and it is not reused. The order of operations changes the meaning of the result, reduce requires an associative operation with a neutral identity value, and mutable accumulation, grouping, and partitioning are done by collectors. Primitive streams avoid boxing, and Gatherers from JDK 24 add stateful intermediate operations, including sliding windows. A parallel stream does not guarantee a speedup and is incompatible with shared mutable state. A pipeline is tested by its observable result and by an independent loop-based implementation, and when the policy is complex, an ordinary loop may be clearer.
Review questions
- Where does a lambda get the types of its parameters?
- How does andThen differ from compose?
- Why can orElse do unnecessary work?
- Which operation starts a pipeline?
- How does takeWhile differ from filter?
- What policy do duplicate keys in toMap require?
- What does windowSliding return for a short source?
- Why doesn't parallelStream automatically fix a slow algorithm?