Example example_reflection
Part of the full Java 9 Jigsaw modules example suite.
|
Authors
Originally written by Martin Lehmann, Kristine Schaal and RĂ¼diger Grammes (cf. original repository). Migrated for Java Modules support documentation of Apache MavenTM in the course of the Maven Support & Care program by Gerd Aschemann (and other team members) as forked repository. Please add discussions, requirements, bugfixes, etc. to the fork instead of the original. |
What is this example about?
Module Dependency Graph, created with DepVis
Example shows …
Before J9 build b136, there was a difference between exports and exports dynamic.
In our example we’ve had a difference between the (exported) package pkgb with class B and the (non-exported) package pkgbinternal with class InternalB.
In modmain, we call methods of both classes statically (only B) and dynamically via reflection (B and InternalB), with variants of methods (public, private, private static methods) are all called via reflection.
In the module-info of modb there is no more distinction possible, both exports are exports private.
Output
This example uses golden master testing to ensure output consistency.
The expected output is compared with actual output using verify.sh.
Expected Output
1. Main: pkgmain.Main, id=ID_Main_22, B: from B.doIt, direct call
2. Main: pkgmain.Main, id=ID_Main_22, B: from B.doIt, call via reflection
3. Main: pkgmain.Main, id=ID_Main_22, B: from B.doItPrivate, call via reflection
4. Main: pkgmain.Main, id=ID_Main_22, B: from B.doItPrivateStatic, static, call via reflection
5. Main: pkgmain.Main, id=ID_Main_22, B1: from B.doIt, direct call
6. Main: pkgmain.Main, id=ID_Main_22, B1: from B.doIt, call via reflection
9. Main: pkgmain.Main, id=ID_Main_22, InternalB: from InternalB.doIt, call via reflection
10. Main: pkgmain.Main, id=ID_Main_22, InternalB: from InternalB.doItPrivate, call via reflection
11. Main: pkgmain.Main, id=ID_Main_22, InternalB: from InternalB.doItPrivateStatic, static, call via reflection
Actual Output
1. Main: pkgmain.Main, id=ID_Main_22, B: from B.doIt, direct call
2. Main: pkgmain.Main, id=ID_Main_22, B: from B.doIt, call via reflection
3. Main: pkgmain.Main, id=ID_Main_22, B: from B.doItPrivate, call via reflection
4. Main: pkgmain.Main, id=ID_Main_22, B: from B.doItPrivateStatic, static, call via reflection
5. Main: pkgmain.Main, id=ID_Main_22, B1: from B.doIt, direct call
6. Main: pkgmain.Main, id=ID_Main_22, B1: from B.doIt, call via reflection
9. Main: pkgmain.Main, id=ID_Main_22, InternalB: from InternalB.doIt, call via reflection
10. Main: pkgmain.Main, id=ID_Main_22, InternalB: from InternalB.doItPrivate, call via reflection
11. Main: pkgmain.Main, id=ID_Main_22, InternalB: from InternalB.doItPrivateStatic, static, call via reflection
Maven 4 Output
1. Main: pkgmain.Main, id=ID_Main_22, B: from B.doIt, direct call
2. Main: pkgmain.Main, id=ID_Main_22, B: from B.doIt, call via reflection
3. Main: pkgmain.Main, id=ID_Main_22, B: from B.doItPrivate, call via reflection
4. Main: pkgmain.Main, id=ID_Main_22, B: from B.doItPrivateStatic, static, call via reflection
5. Main: pkgmain.Main, id=ID_Main_22, B1: from B.doIt, direct call
6. Main: pkgmain.Main, id=ID_Main_22, B1: from B.doIt, call via reflection
9. Main: pkgmain.Main, id=ID_Main_22, InternalB: from InternalB.doIt, call via reflection
10. Main: pkgmain.Main, id=ID_Main_22, InternalB: from InternalB.doItPrivate, call via reflection
11. Main: pkgmain.Main, id=ID_Main_22, InternalB: from InternalB.doItPrivateStatic, static, call via reflection
Maven 4 Migration
This example was migrated to Maven 4 using the standard approach documented in the central Maven 4 Migration guide. The migration required no special configuration beyond the standard Module Source Hierarchy setup.