- All Implemented Interfaces:
- com.google.common.base.FinalizableReference
- Enclosing class:
- AbstractObjectCache
protected abstract static class AbstractObjectCache.SoftKey<T>
extends com.google.common.base.FinalizableSoftReference<T>
Key used in the underlying map. It is essentially a soft reference, with
slightly special properties.
It acts as a proxy for the object it refers to and essentially delegates
to it. There are three exceptions here:
1) This key needs to have a cached hash code. The requirement is that the
key needs to be able to look itself up after the reference to the object
has been cleared (and thus we can no longer look it up from there). One
typical container where we are stored are HashMaps -- and they need it
to be constant.
2) This key does not tolerate checks to see if its equal to null. While we
could return false, we want to catch offenders who try to store nulls
in the cache.
3) This key inverts the check for equality, e.g. it calls equals() on the
object which was passed to its equals(). Instead of supplying itself,
it supplies the referent. If the soft reference is cleared, such check
will return false, which is fine as it prevents normal lookup from
seeing the cleared key. Removal is handled by the explicit identity
check.