de.caff.generics.util

## Class MutableRef<T>

- java.lang.Object
- - de.caff.generics.util.MutableRef<T>

- Type Parameters:
    `T` - type of object kept by this reference
  All Implemented Interfaces:
    IReference<T>

      public class MutableRef<T>
      extends java.lang.Object
      implements IReference<T>

  A mutable reference to an object. This is sometimes useful to return a value from lambdas, although it is usually considered a hack. It is not thread-safe!
  Since:
    October 10, 2022
  Author:
    Rammi

- - ### Field Summary

    - ### Fields inherited from interface de.caff.generics.util.IReference

      `NULL_REF`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `MutableRef()` Constructor creating a `null` reference
    `MutableRef(T reference)` Constructor.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `T` | `get()` Get the referenced object.
    `T` | `require()` Require that the reference value is set to a non-null value.
    `void` | `set(T reference)` Set the reference.

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

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

    - ### Methods inherited from interface de.caff.generics.util.IReference

      `hard, isNull, nullRef, soft, weak`

- - ### Constructor Detail

    - #### MutableRef

          public MutableRef()

      Constructor creating a `null` reference

    - #### MutableRef

          public MutableRef(@Nullable
                            T reference)

      Constructor.
      Parameters:
        `reference` - referenced object

  - ### Method Detail

    - #### set

          public void set(@Nullable
                          T reference)

      Set the reference.
      Parameters:
        `reference` - referenced object

    - #### get

          @Nullable
          public T get()

      Description copied from interface: `IReference`
      Get the referenced object. Depending on the implementation this might return `null` if the referenced object is garbage collected or this is a `null reference`.
      Specified by:
        `get` in interface `IReference<T>`
      Returns:
        referenced object, or `null`

    - #### require

          @NotNull
          public T require()

      Require that the reference value is set to a non-null value.
      Returns:
        referenced value