Package org.apache.groovy.util

# Class ObjectHolder<T>

java.lang.Object
org.apache.groovy.util.ObjectHolder<T>

Type Parameters:
  `T` - the type of object

public class ObjectHolder<T> extends Object
Just hold an object

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ObjectHolder()`
  Creates an empty holder.
  `ObjectHolder(T object)`
  Creates a holder with an initial object.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `T`
  `getObject()`
  Returns the currently held object.
  `T`
  `getObject(Supplier<? extends T> def)`
  Returns the currently held object, initializing it from the supplier when needed.
  `void`
  `setObject(T object)`
  Replaces the currently held object.

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

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

- ## Constructor Details

  - ### ObjectHolder

    public ObjectHolder()
    Creates an empty holder.

  - ### ObjectHolder

    public ObjectHolder(T object)
    Creates a holder with an initial object.
    Parameters:
      `object` - the initial object

- ## Method Details

  - ### getObject

    public T getObject()
    Returns the currently held object.
    Returns:
      the held object

  - ### getObject

    public T getObject(Supplier<? extends T> def)
    Returns the currently held object, initializing it from the supplier when needed.
    Parameters:
      `def` - the supplier used when no object has been set
    Returns:
      the held object

  - ### setObject

    public void setObject(T object)
    Replaces the currently held object.
    Parameters:
      `object` - the object to hold