It is possible to define sealed
classes in Scala, which are basically final
except if the sub-classing happens in the same file.
It seems that the JVM doesn't allow final
class bytecode and subclasses of it.
Considering that there is no "notion" of source file in the bytecode, how is this restriction enforced?
Therefore, how can javac
prevent a Scala sealed
class from being sub-classed in Java?
The restriction is enforced for Scala source by scalac at compile time. The resulting binary class definitions don't have the JVMs final flag set so, as you've probably guessed by now, the sealed restriction will not be enforced by javac when Java sources are compiled against Scala binaries.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With