[records] updates for Preview 6. Default access modes

John Rose john.r.rose at oracle.com
Fri Jan 10 06:51:52 UTC 2020

P.S.  The alert reader has perhaps already said, “but wait, if you
make records like interfaces, then records cannot define non-public
APIs!”  Very good, alert reader, that’s just like interfaces.  And we
can amend *both* by adding some way to overcome the default
“public” with a new modifier that means “I know you default to
public, and I know the normal syntax for package access is to
say nothing and obtain a different default, and I want that package
access, please.”  Potential spellings for that modifier are “package”
and “non-public”.

In interfaces, haven’t you ever wanted to define a non-public nested
class which implements the interface or carries some other interesting
implementation data?  The JVM has no objection to you doing so, but
the language does.  It would be helpful to allow an interface to define
a non-public nested class, for the sake of modularity.  The “package”
or “non-public” modifier would support this.

Even for garden variety classes there’s a use case for such a modifier.
Haven’t you ever wanted to mark an API point, “don’t make this public,
for heaven’s sake”?  I use the comment “/*non-public*/” which drives
maintainers crazy.  Saying “non-public” or “package” would be a better
way to document the intention.

More information about the amber-spec-experts mailing list