Class 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
    • Constructor Detail

      • Mutable

        public Mutable()
        Constructs and returns an empty Mutable. Use set(Object) to add the enclosed object.
      • Mutable

        public Mutable​(T val)
        Constructs and returns a new Mutable containing the given val.
    • Method Detail

      • create

        public static <T> Mutable<T> create()
      • set

        public void set​(T val)
        Sets the enclosed object for an empty Mutable.
      • get

        public T get()
        Returns the value enclosed by this Mutable.
      • hashCode

        public int hashCode()
        Returns a hash code of the Mutable's value.
        Overrides:
        hashCode in class Object
      • equals

        public boolean equals​(Object obj)
        Returns true if this Mutable is equal to the given object.
        Overrides:
        equals in class Object