Class MapBackedClassValue<V>

  • Type Parameters:
    V - the type of the values stored in the Maps.
    All Implemented Interfaces:
    ReadOnlyMap<Class,​V>

    public final class MapBackedClassValue<V>
    extends Object
    implements ReadOnlyMap<Class,​V>
    For efficient lookup based on Class types as key, a ClassValue should be used; however it requires lazy association of values; this helper wraps a plain HashMap but optimises lookups via the ClassValue. N.B. there is a cost in memory and in terms of weak references, so let's use this only where proven that a simple Map lookup is otherwise too costly.
    Since:
    6.2
    • Constructor Detail

      • MapBackedClassValue

        public MapBackedClassValue​(Map<Class<?>,​V> map)
    • Method Detail

      • get

        public V get​(Class key)
        Description copied from interface: ReadOnlyMap
        The main operation.
        Specified by:
        get in interface ReadOnlyMap<Class,​V>
        Returns:
        the corresponding object, or null if there is no association with any entry.
      • dispose

        public void dispose()
        Use this to wipe the backing map, important to avoid classloader leaks.
        Specified by:
        dispose in interface ReadOnlyMap<Class,​V>