A case class is defined by adding the case keyword before the class keyword. Case classes are especially useful when you want to use pattern matching.
- [Instructor] In Scala, there's a variation on the idea…of a class, called a case class.…Case classes are defined by adding the case keyword…before the class keyword.…In your exercise files folder under chapter 04,…0403, you'll see a case class example of that Scala file.…And in there, you can see on line nine,…I have the keyword case, in front of class.…By adding that keyword,…it pre pends val to all parameters.…So all the parameters are considered immutable.…
It automatically creates equals and hash code methods…so that the instances of that class…can safely be used in collections.…So we can add them to a list, an array list.…It also creates a companion object of the same name…with an apply method.…This allows us to create instances…of this class without the key word new,…which can see here on lines four, five and six.…Val Alice equals person…I don't have to say new person.…Another nice feature of case classes…is that we can do pattern matching with case classes.…
So now that we have an example here of a case class,…
Join Peggy Fisher as she helps get you started with Scala, so you can leverage the unique capabilities it offers. First, learn the basics of type inference, variables, loops, functions, and operators. Then, find out how to read files using a console, perform pattern matching, handle exceptions, and more. Finally, learn how to use classes, fields, methods, and objects.
- Integrating with IDEs
- Scala worksheets
- Scala repl sessions
- Type inference
- Creating variables
- Working with loops
- Higher-order functions
- Scala operators
- Working with decision statements
- Handling exceptions using try or catch
- Working with tuples and arrays
- Classes, fields, and methods
Skill Level Intermediate
Java Platforms Compared: SE vs EE vs MEwith Peggy Fisher25m 38s Intermediate
1. Getting Started with Scala
2. Scala Basics
3. More Scala Basics
4. Objects with Scala
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.