Hi, On Fri, Nov 6, 2015 at 9:20 PM, Alex Buckley <alex.buck...@oracle.com> wrote:
> >> >> importcom.bar.Bar; >> public classBaz { >> publicString baz(){return newBar().bar();} >> publicBar bar(){ >> return newBar(); >> } >> } >> > > I expect javac will warn about the bar() method of class Baz. As a public > method in a public type in an exported package, its return type is from > another module (com.bar), yet module com.baz doesn't set up implied > readability to that other module. Anyway, moving on. > As said in Alan's response this is my bad and I missed requires public. > > layer 2: com.foo and com.bar@2 >> -------------------- >> module com.bar {//version2 >> >> exports com.bar; >> } >> >> ------------- >> >> //Bar.java >> >> packagecom.bar; >> >> public classBar { >> publicString bar(){return"bar2";} >> } >> >> ------------- >> >> module com.foo { >> requires com.baz; >> >> exports com.foo; >> >> } >> >> ------------- >> >> Foo.java >> >> packagecom.foo; >> >> importcom.bar.Bar; >> importcom.baz.Baz; >> >> public classMain { >> public static voidmain(String[] args) { >> System.out.println(newBaz().baz()); >> System.out.println(newBar().bar()); >> } >> } >> > > Foo.java should not compile. 'import com.bar.Bar' names a type that is > inaccessible from module foo. This makes the rest of the scenario moot. > >> >> >> I say this is puzzling since with almost the equivalent code I get >> another result. If you want I can show for you in another post. >> > > It is puzzling. By specifying com.bar@2 as one of the root modules in > cfg2, you have managed to get layer2's loader to load the class com.bar.Bar > from com.bar@2. And code in module foo can access that class, despite > module foo not reading any com.bar module. > I sent test files directly to your mail. -- Best Regards, Ali Ebrahimi