Is it possible to provide an implementation of a method using a function object/value? I would like to write something in the spirit of:
abstract class A { def f(x:Int) : Int }
class B extends A { f = identity }
You can use a field of type function like this:
abstract class A { val f: (Int) => Int}
val identity = (x: Int) => x*x
class B extends A { override val f = identity }
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