T - the type of value being referencedpublic class DynamicReference<T> extends Object
| Constructor and Description |
|---|
DynamicReference(T initialValue)
Create a dynamically-scoped reference with the given initial default value.
|
| Modifier and Type | Method and Description |
|---|---|
T |
get()
Retrieve the current value of the reference.
|
String |
toString() |
void |
withValue(T newValue,
Runnable block)
Override the value of the reference while executing the given block.
|
<R> R |
withValue(T newValue,
Supplier<R> block)
Override the value of the reference while executing the given block,
returning the block's value.
|
public DynamicReference(T initialValue)
initialValue - the initial default value to usepublic T get()
public void withValue(T newValue, Runnable block)
newValue - the overridden value to use within the given blockblock - the block to executepublic <R> R withValue(T newValue, Supplier<R> block)
R - the return type of the blocknewValue - the overridden value to use within the given blockblock - the block to executeCopyright © 2015. All rights reserved.