Compilation fails because anonymous class constructor formal parameter has inaccessible type

Georgiy Rakov georgiy.rakov at
Wed Jul 22 14:03:17 UTC 2015


let's consider following example:

    class Test18_2 {private static class MyClass {}public static MyClass
    v1 = new MyClass();Test18_2(MyClass mc) {}}public class Test18
    {public static void main(String[] args) {new Test18_2(Test18_2.v1){};}}

this example fails to compile on JDK9b73 with following error:

    Error:(9, 34) java: Test18_2.MyClass has private access in Test18_2

However according to my understanding compilation should succeed as per 
assertion jls-

    Note that it is possible for the signature of the anonymous
    constructor to refer to an inaccessible type (for example, if such a
    type occurred in the signature of the superclass constructor |cs|).
    This does not, in itself, cause any errors at either compile-time or

It seems to be a javac bug. Could you please tell if you agree.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>
-------------- next part --------------
class Test18_2 {
    private static class MyClass {}
    public static MyClass v1 = new MyClass();
    Test18_2(MyClass mc) {}

public class Test18 {
    public static void main(String[] args) {
        new Test18_2(Test18_2.v1){};

More information about the compiler-dev mailing list