com.opensymphony.xwork2.util

## Class LazyRef<T>

- java.lang.Object
- - com.opensymphony.xwork2.util.LazyRef<T>

- Type Parameters:
    `T` - the type of the lazily computed value
  All Implemented Interfaces:
    Supplier<T>

      public class LazyRef<T>
      extends Object
      implements Supplier<T>

  A thread-safe lazy reference that computes its value on first access using double-checked locking. The cached value can be invalidated via `reset()`, causing the next `get()` call to recompute the value.
  Since:
    6.9.0

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `LazyRef(Supplier<T> factory)` Creates a new LazyRef with the given factory supplier.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `T` | `get()` Returns the cached value, computing it on first access or after a `reset()`.
    `void` | `reset()` Invalidates the cached value so the next `get()` call recomputes it.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### LazyRef

          public LazyRef(Supplier<T> factory)

      Creates a new LazyRef with the given factory supplier.
      Parameters:
        `factory` - the supplier used to compute the value; must not be null

  - ### Method Detail

    - #### get

          public T get()

      Returns the cached value, computing it on first access or after a `reset()`.
      Specified by:
        `get` in interface `Supplier<T>`
      Returns:
        the computed value

    - #### reset

          public void reset()

      Invalidates the cached value so the next `get()` call recomputes it.

Copyright © 2000–2026 Apache Software Foundation. All rights reserved.