Package io.microsphere.util
Class ValueHolder<V>
- java.lang.Object
-
- io.microsphere.util.ValueHolder<V>
-
- Type Parameters:
V- the type of the value being held
public class ValueHolder<V> extends java.lang.ObjectA 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(), andtoString()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 Summary
Constructors Constructor Description ValueHolder()ValueHolder(V value)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(java.lang.Object o)VgetValue()inthashCode()static <V> ValueHolder<V>of(V value)voidreset()voidsetValue(V value)java.lang.StringtoString()
-
-
-
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:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
of
public static <V> ValueHolder<V> of(V value)
-
-