E200: Final Local Def
This error occurs when the final modifier is used on a local definition (inside a method or block).
The final modifier is only meaningful for class members, where it prevents overriding in subclasses. Local definitions inside methods cannot be overridden, so final has no effect and is not allowed.
Example
def example(): Unit =
final val local = 42
Error
-- [E200] Syntax Error: example.scala:2:8 --------------------------------------
2 | final val local = 42
| ^^^
| The final modifier is not allowed on local definitions
Solution
Remove the final modifier from local definitions:
def example(): Unit =
val local = 42
println(local)
If you want an inline constant, use inline val:
def example(): Unit =
inline val local = 42
println(local)
In this article