Search code examples
scalapackage-private

Is it possible to extend a package private class defined in a 3rd party jar in Scala


Is it possible to extend a package private class in scala that is defined in a 3rd party jar. So for instance if a 3rd party jar that my code depends on has some class like so

private [somepackage] A {

}

can I somehow subclass this class in my code?

Thanks


Solution

  • Not according to Programming in Scala 3rd Ed., paraphrased:

    package a
    package b {
      private[a] class B
    }
    

    all code outside the package a cannot access class B

    Note that here, package b is in package a.

    Curiously, this doesn't appear to be the case in the REPL: see this post