Back to Scala3

E063: Only Classes Can Be Abstract

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

3.8.41.2 KB
Original Source

E063: Only Classes Can Be Abstract

This error is emitted when the abstract modifier is used on something other than a class, such as a method or value.

The abstract modifier can only be used for classes. For abstract members (methods, values), simply omit the implementation - they are implicitly abstract when declared without a body in a trait or abstract class.


Example

scala
trait Example:
  abstract def method: Int

Error

scala
-- [E063] Syntax Error: example.scala:2:15 -------------------------------------
2 |  abstract def method: Int
  |               ^
  |abstract modifier can be used only for classes; it should be omitted for abstract members

Solution

scala
// Simply omit abstract for member declarations
trait Example:
  def method: Int
scala
// Use abstract only for class definitions
abstract class Example:
  def method: Int
  def concreteMethod: Int = 42
<!-- 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>