Class Box<T>
- java.lang.Object
-
- com.saperion.common.lang.encapsulation.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
-
-
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()
-
-
-
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 anull
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 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
-
-