Motivation for type-level exports

Neil Bartlett njbartlett at gmail.com
Thu Nov 3 15:20:11 PDT 2011


Dear Jigsaw developers,

I hope this is the correct forum to ask a few questions about the
design of the current Jigsaw prototype.

I'll start with a question about the export clause in
module-info.java. In the grammar[1] it states that exports take a
qualified identifier indicating a package or type name. Could you
please explain why it is a requirement for this to be granular to the
level of individual types, when Java already has the package-private
("default") access modifier to restrict access to types from outside
the package.

It seems that the only possible need for type-level exports could be
one or both of the following:

1. To restrict visibility of a type where package-private access would
otherwise have allowed access. In other words you're talking about
restricting visibility of types to other types in the *same package*
(albeit a package that is split across modules).

2. To hide visibility of a type that has been erroneously made public.
However it would seem far simpler to correct such errors by making the
type non-public. Backwards compatibility cannot be the issue here
because restricting visibility would break users of that type just as
surely as changing its accessibility would.

I would be grateful if you could explain the motivation for this
feature, ideally with examples illustrating why it is needed for JDK
modularisation.

Many thanks,
Neil

[1] http://openjdk.java.net/projects/jigsaw/doc/topics/grammar.html



More information about the jigsaw-dev mailing list