docs.scala-lang
docs.scala-lang copied to clipboard
Clarify terminology for enums with parameters on the parent class
In this page: https://docs.scala-lang.org/scala3/reference/enums/enums.html
Is this example of 'Parameterized enums' really a 'Parameterized enums'?
enum Color(val rgb: Int):
case Red extends Color(0xFF0000)
case Green extends Color(0x00FF00)
case Blue extends Color(0x0000FF)
=================== This is my understanding. Maybe I am wrong. Parameterized enums should have parameters in enum value. Have parameters in the enum type is not 'Parameterized enums'.
This is a 'Parameterized enums':
enum Color(val rgb: Int):
case Red (alfa: Double) extends Color(0xFF0000)
case Green (car: String) extends Color(0x00FF00)
case Blue (bright: Double) extends Color(0x0000FF)
I agree we should clarify the terminology we use to describe enums where the parent class takes parameters (aka shared fields) vs enum cases that take parameters (unique fields per case).