Class ScopedValuesExamples

java.lang.Object
net.jrodolfo.java_evolution.java25.scoped_values.ScopedValuesExamples

public class ScopedValuesExamples extends Object
Demonstrates scoped values, finalized in Java 25 by JEP 506.

This example keeps the code intentionally small so the lifecycle is visible: create a scoped-value key, bind a value to it for one operation, read the value while the operation runs, and observe that the binding is gone afterward.

  • Constructor Details

    • ScopedValuesExamples

      public ScopedValuesExamples()
  • Method Details

    • userInsideScope

      public String userInsideScope(String user) throws Exception
      Binds a user name for the duration of one scoped operation.
      Parameters:
      user - user name to bind while the operation runs
      Returns:
      message created while the user binding is active
      Throws:
      Exception - when the scoped operation fails
    • isUserBound

      public boolean isUserBound()
      Reports whether the user key has a value in the current execution scope.
      Returns:
      true when the current code is running inside a user binding