- Type Parameters:
T- Type of objects in the pool
public class InternPool<T> extends ObjectRepresents a pool of unique objects of type
T. Should only be used if objects of type
Tare immutable and have a
Object.equals(Object)implementation, which returns
trueonly if both objects have the same content.
Inspired by: https://github.com/verhas/intern
Constructors Constructor Description
All Methods Instance Methods Concrete Methods Modifier and Type Method Description
intern(T object)Returns a canonical representation for the object.
internReturns a canonical representation for the object.
A pool of objects of type
T, initially empty, is maintained privately by this class.
When the intern method is invoked, if the pool already contains a object equal to
objectas determined by the
Object.equals(Object)method, then the object from the pool is returned. Otherwise,
objectis added to the pool and a reference to
It follows that for any two objects
intern(a) == intern(b)is
trueif and only if
- a object that has the same contents as
object, but is guaranteed to be from a pool of unique objects of type