Practice 6
If a module want to access to other module’s components, other module have to open or export required packages to caller module.
- exports
-
Makes packages accessible to other modules at compile time or run time.
- opens
-
Makes packages accessible to other modules only at run time including access to private members.
Note
|
Class<?> clazz = Class.forName("com.printer.impl.Printer"); (1)
Class<Printer> clazz = Printer.class; (2)
|
1) Reflective access with exports (public method)
cd module-reflection-exports
2) Reflective access with exports (private method)
cd module-reflection-exports-private
3) Reflective access with opens (private method)
cd module-reflection-opens-private
3) 2) Non-Reflective access with opens (public method)
cd module-reflection-opens-public