-, , , private, , .
- , , .
:
trait A {
protected val foo: Bar
}
:
trait A {
private val foo: Bar = initFoo
protected def initFoo: Bar
}
A val foo. foo initFoo, foo:
trait B extends A {
protected def initFoo: Bar = ???
}
, initFoo - .
, initFoo ( , factory),
A, , - Bar
( , foo equals).
( , , seed fo type Int, , ),
, - initFoo, ( -) .
, , , .
(. http://www.scala-lang.org/api/current/index.html#scala.concurrent.CanAwait).
trait A {
// A "permit" to call fooInit. Only this instance can instantiate InitA
abstract class InitA private[this]()
// Unique "permit"
private implicit def initA: InitA = null
private def foo: Int = fooInit
protected def fooInit( implicit init: InitA ): Int
}
trait B extends A {
protected def fooInit( implicit init: InitA ): Int = 123
}
, B initFoo, , InitA ( A.initA A).
, , , axel22, , ( , - - , , ).