The Stream API in JDK 8 promises to bring a lot of expressive power to the Java language. However, the API and the framework do have some limitations. Compared to frameworks in other languages, some key features are missing, including stateless lambda expressions.
Software Engineering blogger David Hartveld rounds out his series of three posts focusing on Java 8 with one introducing the Stream API, demonstrating its extensive use of lambda expressions. Here, he compares a pre-Java 8 for-loop:
List<Block> blocks = /* ... */;
int sumOfWeights = 0;
for (Block block : blocks) {
if (block.getColor() == Color.RED) {
sumOfWeights += block.getWeight();
}
}