Reputation: 1073
Why is there no java.lang.ref.StrongReference
class in jdk1.7? (see JDK-6392701)
I am trying to implement a behavior that needs to be able to store Objects in different reference strengths. So my first thought was to use a field of type Reference<T>
and asign a Referece with of desired strength. But there is no class for Strong references and extending Reference
manually seems like the completely wrong direction.
The alternative would be to have two field, one that is a Reference
and the other that is of the desired type and have only one set but a Reference
that strongly stores the values would make the code much cleaner.
Upvotes: 3
Views: 264
Reputation: 8171
...and extending Reference manually seems like the completely wrong direction.
It's worse than that. According to the API:
Because reference objects are implemented in close cooperation with the garbage collector, this class may not be subclassed directly.
If you want to be able to store multiple different kinds of references, including strong, in the same structure, the best bet is probably to make your own reference interface and make two implementations: one wrapping a Reference<T>
and one wrapping a normal object.
Upvotes: 2