Class WeakIdentityMap<K,​V>


  • public final class WeakIdentityMap<K,​V>
    extends Object
    Implements a combination of WeakHashMap and IdentityHashMap. Useful for caches that need to key off of a == comparison instead of a .equals.

    This class is not a general-purpose Map implementation! It intentionally violates Map's general contract, which mandates the use of the equals method when comparing objects. This class is designed for use only in the rare cases wherein reference-equality semantics are required.

    • Method Detail

      • newHashMap

        public static final <K,​V> WeakIdentityMap<K,​V> newHashMap()
        Creates a new WeakIdentityMap based on a non-synchronized HashMap.
      • newConcurrentHashMap

        public static final <K,​V> WeakIdentityMap<K,​V> newConcurrentHashMap()
        Creates a new WeakIdentityMap based on a ConcurrentHashMap.
      • clear

        public void clear()
      • containsKey

        public boolean containsKey​(Object key)
      • get

        public V get​(Object key)
      • put

        public V put​(K key,
                     V value)
      • isEmpty

        public boolean isEmpty()
      • remove

        public V remove​(Object key)
      • size

        public int size()