scala - How to access functions from traits? -
i new scala , trying use trait"s". code looks this.
trait codehelper { def functioncall(x: integer){ def valuechecker(){ /*code perform required operation*/ } } }
i access trait main scala class called "valuecreator" follows:
class valuecreator() extends baseclass() codehelper { val value = valuechecker() }
however code not work. error in main class "valuecreator" saying
"not found: value valuechecker"
could please tell me how access function trait? thank in advance time
your definition of valuechecker
inside method, functioncaller
, called nested method. means former method function local , available functioncaller
. if want make visible @ trait
level, you'll need make separate method:
trait codehelper { def functioncall(x: int) { } def valuechecker() { /*code perform required operation*/ } }
although, seems want call functioncaller
perhaps?
class valuecreator extends baseclass codehelper { val value = functioncaller(2) }
as side note, class names in scala pascal case, meaning first letter upper case, not lower case.
Comments
Post a Comment