"Module local" access behaviour in Java 9

Andremoniy :

As the core of Jigsaw project is Java Module System, it would be nice to have an ability to restrict access to particular program elements (classes, methods and fields) within particular module only.

It can be helpful when there are some elements in module which are essentially public for this module, but shouldn't be accessible outside this module.

So I'm talking about next level of access after "package-local", which could be named "module-local".

However brief look at Jigsaw rules and early specs didn't help me to figure out such kind of functionality. More specifically this Modifier specification doesn't contain any new elements.

So is any other possibility to do it in future Java 9?

Mark Reinhold :

A public element (i.e., a class, interface, method, or field) in a non-exported package is, in effect, “module local.” It will be accessible to all other code in the module, but not from outside the module.

There is no way to declare a module-local element in an exported package. A public element of an exported package is accessible from outside the module, a package-private element is still package-private, and there’s no element-level access mode between these two modes. We could define a new such mode but we’ve seen few compelling use cases for it and, moreover, implementing modular access control in the JVM at a granularity finer than that of exported packages would impose significant performance costs.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=451563&siteId=1