<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body style="overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;">
Hi Stephan,
<div><br>
</div>
<div>Thanks for your email. Yes, example 7.5.5-2 is missing information to make it more intelligible; sorry about that. </div>
<div><br>
</div>
<div>But you are on the right track - we can use the simple name C in the uses directive *if it has been exported to M*. As you spotted, the JLS requires that the "read by" relation is reflexive, so that’s how a module exports to itself.</div>
<div><br>
</div>
<div>More concretely, consider this slight expansion of the example:</div>
<div><br>
</div>
<div>
<div style="background-color: rgb(255, 255, 255); line-height: 18px; white-space: pre;">
<div><span style="font-family: Menlo; color: rgb(0, 0, 255);">import</span><span style="font-family: Menlo;"> module M;</span></div>
<div><font face="Menlo"><span style="color: rgb(0, 0, 255);">module</span> M {</font></div>
<div><font face="Menlo"><span style="color: rgb(0, 0, 255);">exports</span> p1 <span style="color: rgb(0, 0, 255);">
to</span> M1;</font></div>
<div><font face="Menlo"><span style="color: rgb(0, 0, 255);">exports</span> p2;</font></div>
<div><font face="Menlo"><span style="color: rgb(0, 0, 255);">exports</span> p3 <span style="color: rgb(0, 0, 255);">
to</span> M;</font></div>
<div><span style="font-family: Menlo;"></span><span style="font-family: Menlo; color: rgb(0, 0, 255);">uses</span><span style="font-family: Menlo;"> C;</span></div>
<div><font face="Menlo">}</font></div>
</div>
<div><br>
</div>
<div>The effect of the import module M declaration is to bring in:</div>
<div><br>
</div>
<div>1. Package p2, because it's exported by M to all comers, including M; and</div>
<div>2. Package p3, because it's exported in a qualified fashion to M.</div>
<div><br>
</div>
<div>And, to answer your question, it does NOT bring in package p1 as that is only exported to M1. In other words (and finally filling in all the details!):</div>
<div><br>
</div>
<div>
<div style="background-color: rgb(255, 255, 255); line-height: 18px; white-space: pre;">
<div><span style="color: rgb(0, 128, 0);"><font face="Menlo">//A.java</font></span></div>
<div><font face="Menlo"><span style="color: rgb(0, 0, 255);">package</span> p1;</font></div>
<div><font face="Menlo"><span style="color: rgb(0, 0, 255);">class</span> A {}</font></div>
<font face="Menlo"><br>
</font>
<div><span style="color: rgb(0, 128, 0);"><font face="Menlo">//B.java</font></span></div>
<div><font face="Menlo"><span style="color: rgb(0, 0, 255);">package</span> p2;</font></div>
<div><font face="Menlo"><span style="color: rgb(0, 0, 255);">class</span> B {}</font></div>
<font face="Menlo"><br>
</font>
<div><span style="color: rgb(0, 128, 0);"><font face="Menlo">//C.java</font></span></div>
<div><font face="Menlo"><span style="color: rgb(0, 0, 255);">package</span> p3;</font></div>
<div><font face="Menlo"><span style="color: rgb(0, 0, 255);">class</span> C {}</font></div>
<font face="Menlo"><br>
<br>
</font>
<div><span style="color: rgb(0, 128, 0);"><font face="Menlo">//module-info.java</font></span></div>
<div><font face="Menlo"><span style="color: rgb(0, 0, 255);">import</span> module M;</font></div>
<div><font face="Menlo"><span style="color: rgb(0, 0, 255);">module</span> M {</font></div>
<div><font face="Menlo"><span style="color: rgb(0, 0, 255);">exports</span> p1 <span style="color: rgb(0, 0, 255);">
to</span> M1;</font></div>
<div><font face="Menlo"><span style="color: rgb(0, 0, 255);">exports</span> p2;</font></div>
<div><font face="Menlo"><span style="color: rgb(0, 0, 255);">exports</span> p3 <span style="color: rgb(0, 0, 255);">
to</span> M;</font></div>
<div><font face="Menlo"><span style="color: rgb(0, 0, 255);">uses</span> A; <span style="color: rgb(0, 128, 0);">
// error</span></font></div>
<div><font face="Menlo"><span style="color: rgb(0, 0, 255);">uses</span> B; <span style="color: rgb(0, 128, 0);">
// ok</span></font></div>
<div><font face="Menlo"><span style="color: rgb(0, 0, 255);">uses</span> C; <span style="color: rgb(0, 128, 0);">
// ok</span></font></div>
<div><font face="Menlo">}</font></div>
</div>
</div>
<div><br>
</div>
<div>Hope this helps, and thanks once again. I’ll clarify the spec.</div>
<div><br>
</div>
<div>Gavin</div>
<div><br>
<blockquote type="cite">
<div>On 18 May 2024, at 14:33, Stephan Herrmann <stephan.herrmann@berlin.de> wrote:</div>
<br class="Apple-interchange-newline">
<div>
<div>Hi Gavin,<br>
<br>
I'm having difficulties interpreting this example:<br>
<br>
import module M;<br>
module M {<br>
   ...<br>
   uses C;<br>
   ...<br>
}<br>
<br>
Literal interpretation would suggest that this imports<br>
"all the public top level classes and interfaces in the following packages:<br>
* The packages exported by the module M to module M. ..."<br>
<br>
The notion of exporting to self does not seem to be defined, is it?<br>
JLS 7 says: "A module categorizes some or all of its packages as exported, which means their classes and interfaces may be accessed from code outside the module." i.e., export regulates accessibility across a module boundary, but in the above example there
 is no such boundary.<br>
<br>
Should the module import still be limited to exported packages? But then: exported to whom? Would a qualified export to some other module M2 hide that package from the module M itself (wrt the module import)?<br>
<br>
At least the requirement that M is read by M is satisfied, according to a comment in JLS 7.3.<br>
<br>
thanks,<br>
Stephan<br>
<br>
<br>
Am 26.04.24 um 12:07 schrieb Gavin Bierman:<br>
<blockquote type="cite">Dear experts:<br>
The first draft of a spec covering JEP 476 (Module Import Declarations (Preview))<br>
https://cr.openjdk.org/~gbierman/jep476/latest/ <https://cr.openjdk.org/~gbierman/jep476/latest/><br>
Feel free to contact me directly or on this list with any comments.<br>
Thanks<br>
Gavin<br>
<blockquote type="cite">On 17 Apr 2024, at 19:58, Mark Reinhold <mark.reinhold@oracle.com> wrote:<br>
<br>
https://openjdk.org/jeps/476<br>
<br>
 Summary: Enhance the Java programming language with the ability to<br>
 succinctly import all of the packages exported by a module. This<br>
 simplifies the reuse of modular libraries, but does not require the<br>
 importing code to be in a module itself. This is a preview language<br>
 feature.<br>
<br>
- Mark<br>
</blockquote>
</blockquote>
<br>
</div>
</div>
</blockquote>
</div>
<br>
</div>
</body>
</html>