Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJimmy Li
126 PointsWhat does "hulk.age = 30" mean exactly at 6:30 in the video?
Andi sets the age of "hulk", an instance of SuperHero, to 30 at 6:30 in the video. I am wondering what "hulk.age = 30" means specifically.
Is he directly setting a variable called "age" in the SuperHero class to 30? If so, why didn't he set the variable called "heroAge" to 30 instead?
Or is he calling the setter for age that we defined as "age_=" earlier? If so, does that mean that ".age" is the syntax to call the setter "age_=" in Scala?
1 Answer
Balázs Góczán
23,670 PointsThere is a field named heroAge in the SuperHero class.
def age_=(newAge: Int): Unit = {
This line is the first line of the setter, because setters in scala are the field name followed by an underscore.