Challenge 3: The Real Scope Difference from Java's Own Stream Laziness — Possible Solution ==================================================================== // java2-4's own Java Streams ARE genuinely lazy -- a pipeline like // numbers.stream().filter(...).map(...) doesn't run any of its // intermediate operations until a terminal operation (collect(), // forEach(), etc.) actually triggers the whole thing. But this // laziness belongs specifically to the Stream API -- it is a // property of THAT particular class of objects, not a property of // the Java language itself. // // Concrete example of ordinary, non-Stream Java code that is NOT // lazy, even in a codebase that uses Streams elsewhere: // // int a = 5 + 5; // computed immediately, right here // int b = expensiveCall(); // expensiveCall() runs RIGHT NOW, // // even if `b` is never used // // anywhere afterward // // Both of these lines evaluate eagerly the instant they're reached -- // Java's own arithmetic, ordinary method calls, and variable // assignments are all strict by default, with no way to defer them // short of manually wrapping them in a Supplier or similar and // choosing to call it later yourself. // // In Haskell, by contrast, `int b = expensiveCall()`'s rough // equivalent -- `let b = expensiveComputation` -- would NOT run // expensiveComputation at all unless b's value is later actually // demanded somewhere. There is no special "lazy variant" of ordinary // binding to opt into -- EVERY binding in Haskell behaves this way, // all the time, by default. That's the real difference in scope: Java // has one deliberately-built lazy API sitting inside an otherwise // fully eager language; Haskell has no eager mode to compare it // against at all -- laziness isn't a feature of a subset of the // language, it's simply how the whole language works. WHY THIS WORKS AS AN ANSWER ------------------------------ This provides a concrete example of ordinary, non-Stream Java code that remains strictly eager, correctly identifying that Java's laziness is confined to one specific API rather than being a language-wide default the way it genuinely is in Haskell -- matching the chapter's own stated scope distinction.