Class Box<T>

  • Type Parameters:
    T - Type of the boxed object
    All Implemented Interfaces:
    java.io.Serializable

    public final class Box<T>
    extends java.lang.Object
    implements java.io.Serializable

    Helper class to box an object. Main purpose is to create an easy standard way for call-by-reference method parameters.

    The box-parameters should be the last parameters of a method by convention to increase readability.

    This implementation is not synchronized. If used by different threads concurrently, external synchronization is necessary.

    Author:
    agz
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      Box()
      Creates a box with a null content.
      Box​(T object)
      Create a box with the specified object as its content.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean equals​(java.lang.Object obj)  
      T get()
      Returns the boxed object.
      int hashCode()  
      void set​(T object)
      Set the specified object as the new content of this box.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • Box

        public Box​(T object)
        Create a box with the specified object as its content.
        Parameters:
        object - object to box
      • Box

        public Box()
        Creates a box with a null content.
    • Method Detail

      • set

        public void set​(T object)
        Set the specified object as the new content of this box.
        Parameters:
        object - new content
      • get

        public T get()
        Returns the boxed object.
        Returns:
        the current content of the box
      • equals

        public boolean equals​(java.lang.Object obj)
        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