Class ValueHolder<V>

  • Type Parameters:
    V - the type of the value being held

    public class ValueHolder<V>
    extends java.lang.Object
    A container class to hold a mutable value of any type. This class is not thread-safe.

    It provides methods to set, get, and reset the value, as well as utility methods like equals(Object), hashCode(), and toString() for general usage.

    Example Usage

    
     // Create an empty ValueHolder for String type
     ValueHolder<String> stringHolder = new ValueHolder<>();
     stringHolder.setValue("Hello");
     System.out.println(stringHolder.getValue());  // Output: Hello
    
     // Create a ValueHolder with an initial value using factory method
     ValueHolder<Integer> intHolder = ValueHolder.of(123);
     System.out.println(intHolder.getValue());     // Output: 123
    
     // Reset the value back to null
     intHolder.reset();
     System.out.println(intHolder.getValue());     // Output: null
     
    Since:
    1.0.0
    Author:
    Mercy
    • Constructor Detail

      • ValueHolder

        public ValueHolder()
      • ValueHolder

        public ValueHolder​(V value)
    • Method Detail

      • getValue

        public V getValue()
      • setValue

        public void setValue​(V value)
      • reset

        public void reset()
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • of

        public static <V> ValueHolder<V> of​(V value)