Module java.base
Package java.lang

Class ScopeLocal.Carrier

java.lang.Object
java.lang.ScopeLocal.Carrier
Enclosing class:
ScopeLocalPREVIEW<T>

public static final class ScopeLocal.Carrier extends Object
Carrier relies on preview features of the Java platform:
  • Carrier refers to one or more preview APIs: ScopeLocal.
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.
An immutable map from a set of ScopeLocals to their bound values. When map() or call() is invoked, the ScopeLocals bound in this set are bound, such that calling the get() method returns the associated value.
  • Method Details

    • where

      public final <T> ScopeLocal.Carrier where(ScopeLocalPREVIEW<T> key, T value)
      Return a new map, which consists of the contents of this map plus a new binding of key and value.
      Type Parameters:
      T - The type of the ScopeLocal
      Parameters:
      key - The ScopeLocal to bind a value to
      value - The new value
      Returns:
      TBD
    • get

      public final <T> T get(ScopeLocalPREVIEW<T> key)
      Search for the value of a binding in this set
      Type Parameters:
      T - the type of the ScopeLocal
      Parameters:
      key - the ScopeLocal to find
      Returns:
      the value
    • call

      public final <R> R call(Callable<R> op) throws Exception
      Runs a value-returning operation with this some ScopeLocals bound to values. Code executed by the operation can use the ScopeLocal.get() method to get the value of the variables. The variables revert to their previous values or becomes unbound when the operation completes.
      Type Parameters:
      R - the type of the result of the function
      Parameters:
      op - the operation to run
      Returns:
      the result
      Throws:
      Exception - if the operation completes with an exception
    • callOrElse

      public final <R> R callOrElse(Callable<R> op, Function<? super Exception,​? extends R> handler)
      Runs a value-returning operation with this some ScopeLocals bound to values. If the operation terminates with an exception e, apply handler to e and return the result.
      Type Parameters:
      R - the type of the result of the function
      Parameters:
      op - the operation to run
      handler - a function to be applied if the operation completes with an exception
      Returns:
      the result
    • run

      public final void run(Runnable op)
      Runs an operation with some ScopeLocals bound to our values. Code executed by the operation can use the ScopeLocal.get() method to get the value of the variables. The variables revert to their previous values or becomes unbound when the operation completes.
      Parameters:
      op - the operation to run