Java enum has name() method but scala 3 doesn't have it.
How to get name of the enum in scala 3?
enum Color:
case Red, Green, Blue
Java enum has name() method but scala 3 doesn't have it.
How to get name of the enum in scala 3?
enum Color:
case Red, Green, Blue
toString() method gives the name of the enum.
enum Color:
case Red, Blue, Yellow
println(Color.Red.toString()) //=> Red
Scala 3 enum can also extend java Enum class and use the name() method.
enum Color extends Enum[Color]:
case Red, Blue, Yellow
println(Color.Red.name()) //=> Red