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

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -