Package com.palantir.util
Class Mutable<T>
- java.lang.Object
-
- com.palantir.util.Mutable<T>
-
- Type Parameters:
T
- the type of the value being enclosed
- All Implemented Interfaces:
Serializable
public class Mutable<T> extends Object implements Serializable
Simple generic class to use in situations where something needs to be final to be passed into a closure. This should be preferred over using an array of size 1 to pass an object around. The reference is also volatile so it can be used for cross-thread purposes.- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <T> Mutable<T>
create()
boolean
equals(Object obj)
Returnstrue
if thisMutable
is equal to the given object.T
get()
Returns the value enclosed by thisMutable
.int
hashCode()
Returns a hash code of theMutable
's value.void
set(T val)
Sets the enclosed object for an emptyMutable
.String
toString()
-
-
-
Constructor Detail
-
Mutable
public Mutable()
Constructs and returns an emptyMutable
. Useset(Object)
to add the enclosed object.
-
Mutable
public Mutable(T val)
Constructs and returns a newMutable
containing the givenval
.
-
-
Method Detail
-
create
public static <T> Mutable<T> create()
-
set
public void set(T val)
Sets the enclosed object for an emptyMutable
.
-
get
public T get()
Returns the value enclosed by thisMutable
.
-
hashCode
public int hashCode()
Returns a hash code of theMutable
's value.
-
equals
public boolean equals(Object obj)
Returnstrue
if thisMutable
is equal to the given object.
-
-