By Alvin Alexander. Last updated: February 1, 2021
As a quick note, objects created with object
are final by default in Scala. I don’t think this is shown in Scala 2, but it’s made clear in the Scala 3 REPL:
scala> final object Foo 1 |final object Foo |^^^^^ |final modifier is redundant for objects // defined object Foo
Because the object
keyword in Scala creates a singleton object, attempting to mark it as final
is redundant. Putting this another way, as described in the Scala Tour, an object defines a class that has exactly one instance.