Back to Scala3

E160: Java Enum Parent Args

docs/_docs/reference/error-codes/E160.md

3.8.41.3 KB
Original Source

E160: Java Enum Parent Args

This error occurs when a class extends java.lang.Enum without providing the required constructor arguments (name and ordinal).

The java.lang.Enum constructor requires two arguments: a String name and an Int ordinal. When manually extending java.lang.Enum (which is only allowed with -source:3.0-migration), these arguments must be provided.

Note: In modern Scala 3, you should use the enum keyword instead of manually extending java.lang.Enum.


Example

scala
final class MyEnum extends java.lang.Enum[MyEnum]

Error

scala
-- [E160] Type Error: example.scala:1:12 ---------------------------------------
1 |final class MyEnum extends java.lang.Enum[MyEnum]
  |            ^
  |not enough arguments for constructor Enum: (name: String, ordinal: Int): Enum[MyEnum]

Solution

scala
// Use Scala 3 enum syntax instead (recommended)
enum MyEnum {
  case Value1, Value2
}
<!-- SOURCE-ONLY: Remove the notice below once this page has been manually updated. --> <aside class="warning"> This reference page was created with LLM assistance - the description of the error code may not be accurate or cover all possible scenarios. </aside>