Executing code on creation in scala trait subclass -


i'd define val in trait gets computed once sub-class 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 computed each instance of ex, no matter parameter x give, after 1. if, p 0 computation.

of course, works def, no longer computed once.

after in example instantiated right away, before ex instantiated - , before looking @ x.

to fix can turn after lazy val, evaluated first time use it.


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -