Sunday, 17 August 2014

Scala Note 9: Auxiliary Constructor


In Scala, every auxiliary constructor must invoke another constructor of the same class as its first action. In other words, the first statement in every auxiliary constructor in every Scala class will have the form "this(...)".
The invoked constructor is either the primary constructor, or another auxiliary constructor that comes textually before the calling constructor. The net effect of this rule is that every constructor invocation in Scala will end up eventually calling the primary constructor of the class.

In Java, a constructor must either invoke another constructor of the same class, or directly invoke a constructor of the superclass, as its first action.
In a Scala class, only the primary constructor can invoke a superclass constructor.

No comments:

Post a Comment