T
- the type of the objects being interned by the instancepublic class Interner<T>
extends java.lang.Object
Helper class that interns objects, that is, returns a canonical
representation of the objects. This works similar to
String.intern()
, but it stores the canonical objects on
the heap instead of in the permgen space to address bug #15956.
Instances of this class are not thread safe.
In contrast to String.intern()
, this class does not attempt
to make objects that are not referenced anymore eligible for garbage
collection. Hence, references to instances of this class should not be
held longer than necessary.
Constructor and Description |
---|
Interner() |
public T intern(T instance)
Intern an object and return a canonical instance of it. For two objects
o1
and o2
, the following always evaluates to
true
:
( o1 == null ) ? ( intern(o1) == null ) : o1.equals(o2) == ( intern(o1) == intern(o2) )
instance
- the object to interninstance