I've written this code in scala:
def push(x: T): Unit = ref.updateAndGet(new UnaryOperator[List[T]] {
override def apply(t: List[T]): List[T] = x :: t
})
And want to rewrite it in a more functional way, like
def push(x: T): Unit = ref.updateAndGet(t => x::t)
But it doesn't work. Is it possible to do such casting correctly?
scala-java8-compat has java8 function converters
import scala.compat.java8.FunctionConverters._
def push(x: T): Unit = ref.updateAndGet(asJavaUnaryOperator(t => x::t))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With