Class ReevaluatingReference<T>

java.lang.Object
org.apache.groovy.internal.util.ReevaluatingReference<T>

@Incubating public class ReevaluatingReference<T> extends Object
This class represents a reference to the most actual incarnation of a Metaclass. INTERNAL USE ONLY.
  • Constructor Details

    • ReevaluatingReference

      public ReevaluatingReference(Class clazz, Supplier<T> valueSupplier, Function<T,SwitchPoint> validationSupplier)
      Stores the suppliers and a weak reference to clazz, then loads the first payload. valueSupplier supplies it and validationSupplier supplies the SwitchPoint that guards the cached handle. Invalidating that switch point makes the next getPayload() load a replacement.
      Parameters:
      clazz - payload class passed to MethodHandles.constant; held only weakly
      valueSupplier - supplies a payload, including the one loaded now
      validationSupplier - supplies the switch point for a payload
  • Method Details

    • getPayload

      public T getPayload()
      Returns the payload from the guarded handle. When the switch point has been invalidated, the fallback loads a new payload, installs a new guarded handle, and returns that payload. A payload may be null when the supplier returns null. Any throwable from the handle is rethrown unchecked.
      Returns:
      the current payload