I am implementing some behavior that can benefit from using weak references of some time. I can give a signal to the classroom user at the time of construction, whether this is the case or not. Since weak reference expansion
reference occurs at first glance, it seems that I can do something like this (this is a cap, I'm not really trying to do this I):
Public Square Container & lt; T & gt; {Private Boolean use; WCF; Private References & lt; T & gt; Referee; Public container (boolean icac) {useWeakRef = isWaak; } Public Zero Store (T Wall) {if (useWaqRef) {ref = new WeakReference & lt; & Gt; (Val); } And {ref = new strong reference However, there is no StrongReference category, and accordingly:
Context items apply in close collaboration With the garbage collector, this class can not be sub-classified directly.
Therefore I can not create my own subclass of reference that holds a strong (general) reference of the object. This means that it is not possible to create a class that hides that it uses a weak (or soft) reference from the collar.
I do not really understand why this class does not exist, a strong reference object should always get the object () unless it is clear () Has not been called. Why is this missing? Is any StrongReference incompatible with the context ? This general reference holder will make things very easy.
You can not subclass the context because it is not a public / protected constructor but an alternative solution:
class StrongReference & lt; T & gt; Leak spreads & lt; T & gt; {Private Final T Guidance; Strongreference (t RevenueCurrer) {super (empty); this. Clear = direction; } @ Override Public T () {Return Direction; } // Apply other methods}
No comments:
Post a Comment