E149: Illegal Redefinition Of Standard Kind

This error occurs when code in the scala package attempts to define a class or object with a name that is reserved for core Scala types.

Reserved names include fundamental types like Any, Nothing, AnyRef, AnyVal, Null, Unit, and other core Scala classes. These names are reserved because they are synthesized by the compiler and have special semantics that cannot be replicated by user-defined classes.


Example

package scala

class Any

Error

-- [E149] Syntax Error: example.scala:3:6 --------------------------------------
3 |class Any
  |      ^^^
  |      illegal redefinition of standard class Any
  |-----------------------------------------------------------------------------
  | Explanation (enabled by `-explain`)
  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  |  "Any" is a standard Scala core `class`
  |  Please choose a different name to avoid conflicts
   -----------------------------------------------------------------------------

Solution

package scala

// Choose a different name that doesn't conflict with reserved names
class MyAny

Note: This error can only occur when defining classes in the scala package. Regular user code in other packages can freely use names like Any without conflict, though this is generally not recommended for clarity.