Module java.base
Package java.lang

Class ScopedValue.Carrier

java.lang.Object
java.lang.ScopedValue.Carrier
Enclosing class:
ScopedValuePREVIEW<T>

public static final class ScopedValue.Carrier extends Object
Carrier is a preview API of the Java platform.
Programs can only use Carrier when preview features are enabled.
Preview features may be removed in a future release, or upgraded to permanent features of the Java platform.
A mapping of scoped values, as keys, to values.

A Carrier is used to accumulate mappings so that an operation (a Runnable or Callable) can be executed with all scoped values in the mapping bound to values. The following example runs an operation with k1 bound (or rebound) to v1, and k2 bound (or rebound) to v2.

    ScopedValue.where(k1, v1).where(k2, v2).run(() -> ... );

A Carrier is immutable and thread-safe. The where method returns a new Carrier object, it does not mutate an existing mapping.

Unless otherwise specified, passing a null argument to a method in this class will cause a NullPointerException to be thrown.

Since:
21