summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/library/scala/ref/Reference.scala8
-rw-r--r--src/library/scala/ref/ReferenceWrapper.scala6
2 files changed, 10 insertions, 4 deletions
diff --git a/src/library/scala/ref/Reference.scala b/src/library/scala/ref/Reference.scala
index daebef9526..aac2e2a32a 100644
--- a/src/library/scala/ref/Reference.scala
+++ b/src/library/scala/ref/Reference.scala
@@ -14,10 +14,12 @@ package scala.ref
* @author Sean McDirmid
*/
trait Reference[+T <: AnyRef] extends Function0[T] {
- def isValid: Boolean
+ @deprecated def isValid: Boolean
+ /** return the underlying value */
def apply(): T
- def get = if (!isValid) None else Some(apply())
- override def toString = if (!isValid) "<deleted>" else apply().toString
+ /** return <code>Some</code> underlying if it hasn't been collected, otherwise <code>None</code> */
+ def get : Option[T]
+ override def toString = get.map(.toString).getOrElse("<deleted>")
def clear(): Unit
def enqueue(): Boolean
def isEnqueued(): Boolean
diff --git a/src/library/scala/ref/ReferenceWrapper.scala b/src/library/scala/ref/ReferenceWrapper.scala
index 4546f4d8fd..004496d95b 100644
--- a/src/library/scala/ref/ReferenceWrapper.scala
+++ b/src/library/scala/ref/ReferenceWrapper.scala
@@ -15,7 +15,11 @@ package scala.ref
*/
trait ReferenceWrapper[+T <: AnyRef] extends Reference[T] {
val underlying: java.lang.ref.Reference
- def isValid = underlying.get != null
+ @deprecated def isValid = underlying.get != null
+ override def get = {
+ val ret = underlying.get.asInstanceOf[T]
+ if (ret eq null) None else Some(ret)
+ }
def apply() = {
val ret = underlying.get.asInstanceOf[T]
if (ret eq null) throw new NoSuchElementException