Back to Scala3

E060: Abstract Member May Not Have Modifier

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

3.8.41.2 KB
Original Source

E060: Abstract Member May Not Have Modifier

This error is emitted when an abstract member is declared with a modifier that is incompatible with being abstract, such as final or private.

Abstract members are meant to be implemented by subclasses, so they cannot be final (which prevents overriding) or private (which prevents access by subclasses).


Example

scala
trait Example:
  final def abstractMethod: Int

Error

scala
-- [E060] Syntax Error: example.scala:2:12 -------------------------------------
2 |  final def abstractMethod: Int
  |            ^
  |            abstract method abstractMethod may not have `final` modifier

Solution

scala
// Remove the incompatible modifier
trait Example:
  def abstractMethod: Int
scala
// Or provide an implementation if you want final
trait Example:
  final 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>