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.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()
, 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 boolean
equals(java.lang.Object o)
V
getValue()
int
hashCode()
static <V> ValueHolder<V>
of(V value)
void
reset()
void
setValue(V value)
java.lang.String
toString()
-
-
-
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 classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
of
public static <V> ValueHolder<V> of(V value)
-
-