Class MapBackedClassValue<V>

  • Type Parameters:
    V - the type of the values stored in the Maps.

    public final class MapBackedClassValue<V>
    extends Object
    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.
    • Constructor Detail

      • MapBackedClassValue

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

      • get

        public V get​(Class<?> key)
      • dispose

        public void dispose()
        Use this to wipe the backing map, but N.B. we won't be clearing the ClassValue: this is useful only to avoid classloader leaks since the Map may hold references to user classes. Since ClassValue is also possibly caching state, it might be possible to retrieve some values after this but shouldn't be relied on. ClassValue doesn't leak references to classes.