Inner classes are allowed to be specified in 'uses' statement

Georgiy Rakov georgiy.rakov at oracle.com
Fri Apr 1 14:52:06 UTC 2016


Hello,

currently inner classes are allowed to be specified in 'uses' statement, 
for instance following code is compiled successfully by JDKb111 javac:

    a/module-info.java:
    module a {
         uses pkg.Outer.Inner;
    }

    a/pkg/Outer.java:
    package pkg;
    public class Outer{ public class Inner{} }

Spec doesn't prevent it either. However in 1.1.3 
<http://cr.openjdk.java.net/%7Emr/jigsaw/spec/lang-vm.html> it prevents 
implementations specified in 'provides' statement to be inner classes. 
According to my understanding inner class cannot be extended by 
non-inner class, for instance "public class Impl extends Outer.Inner { } 
" would cause:

    error: an enclosing instance
    that contains Outer.Inner is required
    class Implem extends Outer.Inner {}
    ^
    1 error

So could you please tell what is the purpose of allowing inner classes 
to be specified in 'uses' statement, there seem to be no way to create 
its implementation. Should it be prohibited by spec?

The minimized testcase is attached; in order to run it please:
1. unzip attached archive on Windows machine;
2. rename test12\test_bat to test12\test.bat;
3. modify test.bat by changing JDK_HOME variable to point to your JDK 
installation;
4. run test.bat.

Thank you,
Georgiy.


More information about the jigsaw-dev mailing list