What methods are generated for Scala case classes?
I know that some methods are generated specifically for case classes:
What are the others?
Also, I see that I can call productArity() on any case class. How does this work? In other words, why the following code is valid?
case class CaseClass()
object CaseClass {
val cc = new CaseClass()
cc.productArity
}
A good way what methods are generated for a specific class in Scala is to use the javap command.
Find the .class file that was compiled by scalac and then run the javap -private command on it from your respective command line tool. This will show you the constructors, fields, and all methods for a class.
You can do this for your case class to see what kinds of things are automagically supplied by Scala.
Case classes mixin the Product trait which provides the productArity method. For case classes the productArity method will return the count of the parameter list supplied in the class definition.
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