J.VI · Java 25 practice question

An application passes a security token from a controller through six intermediate service layers to a repository method. What drawback of standard method-parameter passing does ScopedValue<T> help eliminate?

Choose one answer
Check answer and explanation

Correct answer: Every intermediate method in the call chain must declare the parameter and thereby gains access to the data.

Explanation

Passing data through method parameters forces every intermediate method in the sequence to declare that parameter and exposes the data to each of them, which ScopedValue avoids.

Common trap

Claiming a four-frame limit on reference parameters is tempting as a fabricated JVM constraint, but Java imposes no such limit on method parameters. Claiming the JVM deep-copies objects on each call is tempting to developers thinking of pass-by-value semantics in other languages, whereas Java passes object references without deep copying.

Source: Java SE 25 API: ScopedValue
Checked against the cited text on 2026-11-25.

Report an error in this question