ContentsTopThe Scala package objectRestrictions and things to comeContents

Restrictions and things to come

Package objects as currently implemented have some restrictions. First, you cannot define or inherit overloaded methods in package objects. Second, you cannot define or inherit a member in a package object which is also the name of a top-level class or object in same package. We expect that some future Scala release will drop these restrictions.

An interesting question is what should happen when the name of a top-level class or object in a package is redefined in the associated package object. For the moment, this is simply forbidden. But if we wanted to allow this, it would make sense to take the definition in the package object as the public interface of the definition in the package itself. Code from within the package could see the full definition, but code from outside the package could only see what's defined in the package object. That way, package objects could evolve into the backbone of a fairly advanced module system, which allows to flexibly combine interfaces with implementations.

Of course, this remains to be done, and the details remain to be worked out, but it opens up interesting possibilities.


ContentsTopThe Scala package objectRestrictions and things to comeContents