Because of inheritance linearization in Scala, I would like to understand how traits I specify for a case class are ordered relative to the two traits automatically generated and added by the Scala compiler; i.e. Product with Serializable
(and disappointingly, it's not ProductN[...]
as of 2.12).
I've searched through pretty thoroughly and I haven't found it directly addressed. Given the following:
case class Cc(a: Int, b: Int) extends MyTraitA with MyTraitB
Following the Scala compiler automatic code generation, which of these is the correct assumption about the resulting inheritance ordering?
case class Cc(a: Int, b: Int) extends MyTraitA with MyTraitB with Product with Serializable
case class Cc(a: Int, b: Int) extends Product with Serializable with MyTraitA with MyTraitB
And then, I have an additional question. What undesirable or unexpected effects could occur if I were to explicitly extend Product2[...]
to the case class? Here are the two above pieces of code repeated with Product2[...]
inserted:
case class Cc(a: Int, b: Int) extends MyTraitA with MyTraitB with Product2[Int, Int] with Product with Serializable
case class Cc(a: Int, b: Int) extends Product with Serializable with MyTraitA with MyTraitB with Product2[Int, Int]
IOW, is there any sort of undesirable interactions because both Product
and Product2
appear together?