opaque type WeakRef[A]

Weakly Referenced Instance

J.WeakRef value will be garbage collected in case there is no other reference to it

Note. The returned getOpt should be used for basic checks only. It should not be subjected to chain transformations, as this creates more references to the weak value

 var hr = new Object       // hard reference

 val wr = J.WeakRef(hr)    // weak reference

 wr.getOpt.isEmpty.tp       // Prints: false

 hr = null                 // Clearing hard refference
 System.gc                 // Run garbage collection

 wr.getOpt.isEmpty.tp       // Prints: true


def getOpt[A]: Opt[A]

Value Option

Value Option

Returns value option