233. Chaining and rebinding scoped values
In this problem, you’ll see how to chain and rebind scoped values. These are very handy operations that you’ll love to use.
Changing scoped values
Let’s assume that we have three ScopedValue
instances, as follows:
private static final ScopedValue<String> SCOPED_VALUE_1
= ScopedValue.newInstance();
private static final ScopedValue<String> SCOPED_VALUE_2
= ScopedValue.newInstance();
private static final ScopedValue<String> SCOPED_VALUE_3
= ScopedValue.newInstance();
We also have a Runnable
that uses all three ScopedValue
instances:
Runnable task = () -> {
logger.info(Thread.currentThread().toString());
logger.info(() -> SCOPED_VALUE_1.isBound()
? SCOPED_VALUE_1.get() : "Not bound");
logger.info(() -> SCOPED_VALUE_2.isBound()
? SCOPED_VALUE_2.get() : "Not bound");
logger.info(() -> SCOPED_VALUE_3.isBound()
? SCOPED_VALUE_3...