E157: Cannot Extend Java Enum

This error occurs when a class tries to extend java.lang.Enum directly. In Scala 3, only enums defined with the enum syntax are allowed to extend Java's Enum class.

This restriction ensures that Scala enums follow proper semantics and benefit from compiler support for exhaustiveness checking and other enum-specific features.


Example

class MyEnum extends java.lang.Enum[MyEnum]

Error

-- [E157] Syntax Error: example.scala:1:6 --------------------------------------
1 |class MyEnum extends java.lang.Enum[MyEnum]
  |      ^
  |class MyEnum cannot extend java.lang.Enum: only enums defined with the enum syntax can

Solution

// Use Scala 3 enum syntax instead
enum MyEnum {
  case Value1, Value2, Value3
}
// For Java interop, Scala 3 enums automatically extend java.lang.Enum
enum Color {
  case Red, Green, Blue
}

// Color cases are instances of java.lang.Enum[Color]