Package org.codehaus.groovy.util

# Class LazyReference<T>

java.lang.Object
java.util.concurrent.locks.AbstractOwnableSynchronizer
java.util.concurrent.locks.AbstractQueuedSynchronizer
org.codehaus.groovy.util.LockableObject
org.codehaus.groovy.util.LazyReference<T>

All Implemented Interfaces:
  `Serializable`

public abstract class LazyReference<T> extends LockableObject
Soft reference with lazy initialization under lock

See Also:
  - Serialized Form

- ## Nested Class Summary

  ## Nested classes/interfaces inherited from class java.util.concurrent.locks.AbstractQueuedSynchronizer

  `AbstractQueuedSynchronizer.ConditionObject`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `LazyReference(ReferenceBundle bundle)`
  Creates a lazily initialized reference that stores computed values using the supplied bundle.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `clear()`
  Discards the cached state so the next `get()` call recomputes it.
  `T`
  `get()`
  Returns the current value, initializing or recreating it when necessary.
  `abstract T`
  `initValue()`
  Computes the value to cache for future `get()` calls.
  `String`
  `toString()`
  Returns the current cached value as a string, or `<null>` when no value is available.

  ### Methods inherited from class org.codehaus.groovy.util.LockableObject

  `isHeldExclusively, lock, tryAcquire, tryRelease, unlock`

  ### Methods inherited from class java.util.concurrent.locks.AbstractQueuedSynchronizer

  `acquire, acquireInterruptibly, acquireShared, acquireSharedInterruptibly, compareAndSetState, getExclusiveQueuedThreads, getFirstQueuedThread, getQueuedThreads, getQueueLength, getSharedQueuedThreads, getState, getWaitingThreads, getWaitQueueLength, hasContended, hasQueuedPredecessors, hasQueuedThreads, hasWaiters, isQueued, owns, release, releaseShared, setState, tryAcquireNanos, tryAcquireShared, tryAcquireSharedNanos, tryReleaseShared`

  ### Methods inherited from class java.util.concurrent.locks.AbstractOwnableSynchronizer

  `getExclusiveOwnerThread, setExclusiveOwnerThread`

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

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

- ## Constructor Details

  - ### LazyReference

    public LazyReference(ReferenceBundle bundle)
    Creates a lazily initialized reference that stores computed values using the supplied bundle.
    Parameters:
      `bundle` - the reference strategy to use after initialization

- ## Method Details

  - ### get

    public T get()
    Returns the current value, initializing or recreating it when necessary.
    Returns:
      the current value, which may be `null`

  - ### clear

    public void clear()
    Discards the cached state so the next `get()` call recomputes it.

  - ### initValue

    public abstract T initValue()
    Computes the value to cache for future `get()` calls.
    Returns:
      the value to cache, or `null` to cache a null result

  - ### toString

    public String toString()
    Returns the current cached value as a string, or `<null>` when no value is available.
    Overrides:
      `toString` in class `AbstractQueuedSynchronizer`
    Returns:
      a string form of the cached value