J.VI · Java 25 practice question
A developer creates `ScopedValue<String> sv = ScopedValue.newInstance();` on the main thread and then checks `sv.isBound()` inside a newly started virtual thread without calling `where`. What does it print?
void main() throws InterruptedException {
ScopedValue<String> sv = ScopedValue.newInstance();
Thread.startVirtualThread(() -> System.out.println(sv.isBound())).join();
}
Check answer and explanation
Correct answer: false
Explanation
`ScopedValue.newInstance()` creates a scoped value that is initially unbound for all threads, including virtual threads, so `isBound()` prints `false`.
Common trap
Starting a virtual thread does not bind an unbound `ScopedValue`, and `isBound()` returns a `boolean`, not `null`.
Source: Java SE 25 API: ScopedValue.newInstance
Checked against the cited text on 2026-11-27.