Example example_derived_private-package-protected
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?
statuc vs. dynamic type
Module Dependency Graph, created with DepVis
Example shows …
Type visibility: DataFactory in the exported package pkgb of modb returns (from different create methods)
-
Data as Data (from pkgb). Visible in modmain.
-
InternalData (from pkgbinternal which is not exported) as Data. Visible in modmain as Data. Acts as InternalData (keeps its type), but only methods from Data are visible. E.g. a cast to InternalData would not work in modmain.
-
InternalData as InternalData. May be called from modmain, as long as the type InternalData is not used. Some static methods (e.g. getName) may even be called, other like toString not. Not really obvious why.
Output
This example uses golden master testing to ensure output consistency.
The expected output is compared with actual output using verify.sh.
Expected Output
Main: pkgmain.Main, id=ID_Main_14, B: from B
Main: pkgmain.Main, id=ID_Main_14, B: from pkgbinternal.InternalBHelper
Main: pkgmain.Main, id=ID_Main_14, B: from pkgbinternal.InternalBSuperClass
Main: pkgmain.Main, id=ID_Main_14, B: from B, but only protected
doItNotOverwritten
Main: pkgmain.Main, id=ID_Main_14, Factory.createData(): is Data
Main: pkgmain.Main, id=ID_Main_14, Factory.createInternalDataAsData(): is InternalData
Main: pkgmain.Main, id=ID_Main_14, Factory.createInternalData2(): pkgbinternal.InternalData, id=ID_DataFactory_17
Actual Output
Main: pkgmain.Main, id=ID_Main_14, B: from B
Main: pkgmain.Main, id=ID_Main_14, B: from pkgbinternal.InternalBHelper
Main: pkgmain.Main, id=ID_Main_14, B: from pkgbinternal.InternalBSuperClass
Main: pkgmain.Main, id=ID_Main_14, B: from B, but only protected
doItNotOverwritten
Main: pkgmain.Main, id=ID_Main_14, Factory.createData(): is Data
Main: pkgmain.Main, id=ID_Main_14, Factory.createInternalDataAsData(): is InternalData
Main: pkgmain.Main, id=ID_Main_14, Factory.createInternalData2(): pkgbinternal.InternalData, id=ID_DataFactory_17
Maven 4 Output
Main: pkgmain.Main, id=ID_Main_14, B: from B
Main: pkgmain.Main, id=ID_Main_14, B: from pkgbinternal.InternalBHelper
Main: pkgmain.Main, id=ID_Main_14, B: from pkgbinternal.InternalBSuperClass
Main: pkgmain.Main, id=ID_Main_14, B: from B, but only protected
doItNotOverwritten
Main: pkgmain.Main, id=ID_Main_14, Factory.createData(): is Data
Main: pkgmain.Main, id=ID_Main_14, Factory.createInternalDataAsData(): is InternalData
Main: pkgmain.Main, id=ID_Main_14, Factory.createInternalData2(): pkgbinternal.InternalData, id=ID_DataFactory_17
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.