When I right-click and follow New->Scala Class, Intellij defaults to creating a new regular class. I'd like it to default to creating a case class.
A small thing... but annoying when creating a lot of new classes.
Is it configurable somewhere?
Scala case classes are just regular classes which are immutable by default and decomposable through pattern matching. It uses equal method to compare instance structurally. It does not use new keyword to instantiate object. All the parameters listed in the case class are public and immutable by default.
On the Project pane on the left, right-click src and select New => Scala class. If you don't see Scala class, right-click on HelloWorld and click on Add Framework Support…, select Scala and proceed. If you see Error: library is not specified, you can either click download button, or select the library path manually.
Defining a case class Notice how the keyword new was not used to instantiate the Book case class. This is because case classes have an apply method by default which takes care of object construction. When you create a case class with parameters, the parameters are public val s. You can't reassign message1.
A class can extend another class, whereas a case class can not extend another case class (because it would not be possible to correctly implement their equality).
File>Settings
and go to Files and Code Templates
.New > Scala Class
. Dialog should have now option Scala Case Class.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With