Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
In this video, weβll take a look at how to create a Scala class along with primary and auxiliary constructors.
New Terms:
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.
Further Reading:
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up