Class SetOnce<T>

  • All Implemented Interfaces:
    Cloneable

    public final class SetOnce<T>
    extends Object
    implements Cloneable
    A convenient class which offers a semi-immutable object wrapper implementation which allows one to set the value of an object exactly once, and retrieve it many times. If set(Object) is called more than once, SetOnce.AlreadySetException is thrown and the operation will fail.
    • Method Detail

      • set

        public void set​(T obj)
        Sets the given object. If the object has already been set, an exception is thrown.
      • trySet

        public boolean trySet​(T obj)
        Sets the given object if none was set before.
        Returns:
        true if object was set successfully, false otherwise
      • get

        public T get()
        Returns the object set by set(Object).