Classes and Constructors8:59 with andi mitre
In this video, we’ll take a look at how to create a Scala class along with primary and auxiliary constructors.
Auxiliary constructors -- In Scala, auxiliary constructors refer to secondary or additional constructors which accept different parameters from the primary constructor. They are defined using ‘def this()’ and always call either the primary constructor or another previously defined auxiliary constructor.
Case classes -- Case classes are standard Scala classes with some boilerplate functionality. When you create a case class the compiler creates a companion object along with an apply method. Constructor parameters become fields and the case class is immutable but contains implementations of hashcode(), toSting() and equals(). Case classes can be instantiated without a new keyword and they are ideal to use with pattern matching.
You need to sign up for Treehouse in order to download course files.Sign up