Scala private subclass class in external projects

Indication of Scala documentation:

A sealed class cannot be directly inherited, unless the inheriting template is defined in the same source file as the inherited class. However, subclasses of a private class can be inherited anywhere.

If I create a hierarchy of sealed classes in my project, all this is fine, for example:

sealed abstract class Base {}
sealed class Derived extends Base {}

But what if I compile the project and distribute it like, say, a JAR in Maven.

What if I write a Java class in a second project that has a JAR in the classpath:

public class Breaker extends Derived {}

Will it compile aka, will the hold still hold? What if I wrote Breakerin Scala?

If sealing works in the situations described in abouve, how to do it?

+4
2

Java sealed, Java sealed, , .

sealed Scala/Java. , (.. Scala , , , , , , versa, , Scala, Scala, , Scala, ), .

, O (n²) , , , , , . , , . Unix C structs + C CLI CIL Java - JVM.

, Scala Java - JVM, , , , - JVM. sealed .

Scala sealed , Java , , Java! ( , , Java, Scala).

+4

sealed , javap RuntimeVisibleAnnotations, , Scala Java sealed, :

, , Scala, .

javap , .

+1

Source: https://habr.com/ru/post/1538521/


All Articles