scala - Why can't I access my objects member variable? -
scala - Why can't I access my objects member variable? -
i have next class setup:
class myclass { class myinnerclass(membervar: string) def getainner: myinnerclass = { new myinnerclass("hello") } }
then have next code outside of class:
def myfunction = { val = new myclass val b = a.getainner.membervar // value membervar not fellow member of a.myinnerclass }
why this?
you need add together keyword val
create membervar
public otherwise it's private value:
class myclass { class myinnerclass(val membervar: string) def getainner: myinnerclass = { new myinnerclass("hello") } }
scala
Comments
Post a Comment