1
The java.lang.ref package offers classes that model reference types in Java, such as Reference, Softreferece, Weakreference and Phantomreference.
Still not familiar with these references in Java? See this question: Canonicalized Mapping and Weakreference
One of the classes of Java SE using Weakreference is the java.util.WeakHashMap
, where we have the key
as weak reference, that is, even with reference the same is collected in the next cycle of the Garbase Collector (if there is no other Strongreference).
"...a Weakhashmap may behave as though an Unknown thread is Silently removing eccentries."
Fonte Javadocs: http://docs.oracle.com/javase/7/docs/api/java/util/WeakHashMap.html
Interestingly, we don’t have a Set implementation with this semantics - Weakset, at least not on the Java SE platform.
How then can we get a Weakset instance?