The only thing I know about PhantomReference
is,
get()
method, it will always return null
It is common to use WeakReference
where PhantomReference
is more appropriate. This avoids certain problems of being able to resurrect objects after a WeakReference
is cleared/enqueued by the garbage collector. Usually the difference doesn't matter because people are not playing silly buggers.
Using PhantomReference
tends to be a bit more intrusive because you can't pretend that the get
method works. You can't, for example, write a Phantom[Identity]HashMap
.