module-info.javaã®ãã£ã¬ã¯ãã£ãã¾ã¨ã
JavaOne 2016ã«æ¥ã¦ãã¾ãï¼
å»å¹´ã¯Jigsawã®ã»ãã·ã§ã³åã£ã¦ãï¼ã¯ã¦ãªã並ã¶ã°ã£ããã§ãããï¼æå¤ã¨Jigsawã®è©±ãåããããã«ãªã£ã¦ãã¾ããï¼
module-info.javaã®ãã£ã¬ã¯ãã£ã(requiresã¨ã)ã®ç°¡åãªã¾ã¨ãã§ãï¼
exports
module m { exports p; }
packageãä»ã®ã¢ã¸ã¥ã¼ã«ããã¢ã¯ã»ã¹å¯è½ã«ãã¾ãï¼
ã¨ã¯ã¹ãã¼ããããããã±ã¼ã¸å
ã®publicã¯ã©ã¹ã¯å«ãã¢ã¸ã¥ã¼ã«ããªã¼ã(å¾è¿°)ã§ããã°ï¼ã¢ã¯ã»ã¹å¯è½ã§ãï¼
exports to ...
module m { exports p to m1, m2; }
packageãç¹å®ã®moduleããã®ã¿ã¢ã¯ã»ã¹å¯è½ã«ãã¾ãï¼
exports private
以ä¸ã®ããã«é常ã®exportsã§ã¯ï¼ä»ã®ã¢ã¸ã¥ã¼ã«ãprivateãªãã£ã¼ã«ããã¡ã½ããã«å¯¾ãã¦ãªãã¬ã¯ã·ã§ã³ã§ã¢ã¯ã»ã¹æ¨©ãä»ä¸ãããã¨ããã¨ï¼å®è¡æä¾å¤ãçºçããããã«ãªãã¾ãï¼
package m1.p; class C { private String field = "..."; }
module m1 { exports m1.p; }
package m2; class UsePrivate { void method() { C c = ...; Field field = c.getClass().getDeclaredField("field"); field.setAccessible(true); // throws Exception } }
exports privateãç¨ããã¨ãããå¯è½ã«ãªãã¾ãï¼
module m1 { exports m1.p; }
package m2; class UsePrivate { void method() { C c = ...; Field field = c.getClass().getDeclaredField("field"); field.setAccessible(true); // throws Exception } }
exports private to ...
ã¢ã¸ã¥ã¼ã«å¶éä»ãexportsãã¤privateãªè¦ç´ ã¸ã®ã¢ã¯ã»ã¹æ¨©éä»ä¸ãå¯è½ã«ãã¾ãï¼
requires
moduleãèªã¿è¾¼ã¿ã¾ãï¼
requiresããã¢ã¸ã¥ã¼ã«å
ã§moduleå
ã§ã¨ã¯ã¹ãã¼ããããã¯ã©ã¹ã«ã¢ã¯ã»ã¹å¯è½ã«ãªãã¾ãï¼
requires transitive
æ¨ç§»çãªmoduleã®èªã¿è¾¼ã¿ã§ãï¼
requires transitiveãè¨è¿°ãããã¢ã¸ã¥ã¼ã«ãèªã¿è¾¼ãã ã¢ã¸ã¥ã¼ã«ã¯requires transitiveã§æå®ãããmoduleãèªã¿è¾¼ã¿ã¾ãï¼
ã¢ã¸ã¥ã¼ã«mãããï¼ã¢ã¸ã¥ã¼ã«m1ãmãrequires transitiveã§èªã¿è¾¼ãã§ããã¨ãã¾ãï¼
module m { exports my.library; }
module m1 { requires transitive m; }
ãã®æm2ãm1ãèªã¿è¾¼ãã¨ï¼æ¨ç§»çã«mãèªã¿è¾¼ã¿ï¼my.libraryããã±ã¼ã¸ã®ã¢ã¯ã»ã¹ãå¯è½ã«ãªãã¾ãï¼
module m2 {
requires m1; // æ¨ç§»çã«mãèªã¿è¾¼ã
}
requires static
moduleãèªã¿è¾¼ã¿ã¾ããï¼ã³ã³ãã¤ã«æã®ã¿ã«moduleã®åå¨ãå¿
é ã§ãï¼
é常ã®requiresã§ã¯ï¼moduleãåå¨ãã¦ããªããã°ã³ã³ãã¤ã«æãã©ã³ã¿ã¤ã æã«ã¨ã©ã¼ã¨ãªãã¾ãï¼
ã©ã³ã¿ã¤ã æã«moduleãåå¨ããªãã¦ãè¯ãå ´åã«ï¼ããã使ãã¾ãï¼
å ·ä½çãªã¦ã¼ã¹ã±ã¼ã¹ã¯ããåãããªãã§ããã©ï¼ã³ã³ãã¤ã«æã«ã®ã¿æå¹ãªã¢ããã¼ã·ã§ã³ã使ãã¨ãã¨ãããªãã»ã»ã»ï¼
åè
Java Platform Module System: Issue Summary
Proposal: #CompileTimeDependences: `requires static`
ããã«ä¸ãã以å¤ã«ãï¼provides withãusesãããã¾ãï¼
ãããã«ã¤ãã¦ã¯JigsawでSPIを使用する - きつねとJava!ãåèãã ããï¼