java.lang.Object
com.saperion.common.lang.encapsulation.Box<T>
Type Parameters:
T - Type of the boxed object
All Implemented Interfaces:
Serializable

public final class Box<T> extends Object implements 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:
  • 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

    Modifier and Type
    Method
    Description
    boolean
     
    get()
    Returns the boxed object.
    int
     
    void
    set(T object)
    Set the specified object as the new content of this box.
     

    Methods inherited from class java.lang.Object

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

    • 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 Details

    • 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(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object