3

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.

Blank Chisui
  • 1,043
  • 10
  • 25

1 Answers1

2

...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.

BambooleanLogic
  • 7,530
  • 3
  • 30
  • 56
  • plus it's in the `java.lang` package and the constructures are package private so you would have to do some real criminal stuff to get it compiled and loaded in the first place. – Blank Chisui Jun 13 '14 at 09:35