J.IX · Java 25 practice question
What does the following Java 25 program print after a `ScopedValue` binding exits its `run` block?
void main() {
ScopedValue<String> KEY = ScopedValue.newInstance();
ScopedValue.where(KEY, "v1").run(() -> {});
System.out.println(KEY.isBound());
}
Check answer and explanation
Correct answer: false
Explanation
Once the `run` block finishes, the scoped value is no longer bound, matching JEP 506's Comprehensibility goal that the lifetime of shared data is apparent from the code structure.
Common trap
Unlike `ThreadLocal`, `ScopedValue` does not remain bound after the dynamic scope exits.
Source: JEP 506: Scoped Values — Goals
Checked against the cited text on 2026-11-27.