object RefExtractor extends App {
class Ref[T](val ref: AtomicReference[T]) extends AnyVal {
def get(): T = {
println("call ref.get")
ref.get()
}
def isEmpty: Boolean = {
println("call ref.get")
ref.get() == null
}
def set(value: T): Unit = ref.set(value)
}
object Ref {
def unapply[T](ref: AtomicReference[T]): Ref[T] = new Ref(ref)
}
val ref = new AtomicReference("hello")
ref match {
case Ref(value) => println(value)
}
}
But what if the x
is not directly available?
then you will see:
call ref.get
call ref.get
hello
It would be nice to save one of the call ref.get
, @odersky is that possible? I knew this is possible at bytecode level, not sure how to express it at language.