I'd like to define a val in a trait that gets computed once by sub-class that gets instantiated.
For instance :
trait Example
{
val p : Int
val after : Int = p + 1
}
class Ex(x : Int) extends Example
{
val p = x
}
I want after to be computed for each instance of Ex, but no matter which parameter x I give, after is always 1. As if, p was 0 for the computation.
Of course, it works with def, but then it is no longer computed only once.