Class Intern<T>


  • public class Intern<T>
    extends java.lang.Object
    Manages manually interning Objects (like String.intern()) except this implemenation avoids the following pitfalls with String.intern()
    • Objects are not interned into the permgen (the permgen is independent of the normal heap and limited to 64MB by default), so using String.intern too often can result in OutOfMemory errors when you have plently of free space
    • This implemenation is faster than String.intern since it doesn't have to deal with garbage collecting weak references
    Disadvantages of this implemenation include
      No automatic garbage collection of Objects. Instead, you must discard the refernce to this Intern object to allow Objects to be garbage collected
    This class is thread safe.
    • Constructor Summary

      Constructors 
      Constructor Description
      Intern()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()
      Clears the intenal cache of interned Objects.
      T intern​(T objectToIntern)
      Interns an object.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Intern

        public Intern()
    • Method Detail

      • intern

        public T intern​(T objectToIntern)
        Interns an object.
        Parameters:
        objectToIntern - the object to intern
        Returns:
        the objectToIntern passed to a previous call to this method if that Object was equal to this Object or objectToIntern if this Object has not been previously interned.
      • clear

        public void clear()
        Clears the intenal cache of interned Objects.