Java Magazine, September/October 2017
ORACLE COM JAVAMAGAZINE SEPTEMBER OCTOBER 2017 23 java 9 A key motivation of the module system is strong encapsulation By default a type in a module is not accessible to other modules unless its a public type and you export its package You expose only the packages you want to expose With Java 9 this also applies to reflection Allowing runtime only access to a package An opens module directive of the form opens package indicates that a specific packages public types and their nested public and protected types are accessible to code in other modules at runtime only Also all the types in the specified package and all of the types members are accessible via reflection Allowing runtime only access to a package by specific modules An opens to module directive of the form opens package to comma separated list of modules indicates that a specific packages public types and their nested public and protected types are accessible to code in the listed modules at runtime only All of the types in the specified package and all of the types members are accessible via reflection to code in the specified modules Allowing runtime only access to all packages in a module If all the packages in a given module should be accessible at runtime and via reflection to all other modules you may open the entire module as in open module modulename module directives Reflection Defaults By default a module with runtime reflective access to a package can see the packages public types and their nested public and protected types However the code in other modules can
You must have JavaScript enabled to view digital editions.