How to understand this Scala function call -


i scala beginner. below scala code runs well, cannot understand it. log shows, line 19 run line 12. how be?

object testclassdef {   class person {     private var _age = 0     def age:int = _age     def age_=(newage: int) = {       _age = newage       println("age changed " + _age)       // line 12     }   }    def main(args: array[string]) {     var p = new person() //    p.age_=(25)     p.age = 26                                // line 19   } } 

if question correctly, you're surprised method called when assign value on line 19. because _= (at end of age function int parameter) means it's assignment operator (also see what uses of underscore in scala?) make sense it's called when type p.age = 26.


Comments