Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8081521

Compiler has trouble compiling nested diamond allocation constructs involving anonymous classes.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 9
    • 9
    • tools
    • b60
    • 9
    • b69
    • Verified

        Let's consider following example:

        class Clazz2 {
            private static class A {};
            public A a;
        }

        public class Test2 {
            static class FooNest<Q> {
                FooNest(Q q, Foo<Q> foo) { }
            }

            static class Foo<T> { }

            static Clazz2 clazz = new Clazz2();

            public static void test() {
                FooNest fooNest = new FooNest<>(clazz.a, new Foo<>() {});
            }
        }

        When it's compiled by JDK9b66 following messages are produced:

        Error:(16, 17) java: Clazz2.A has private access in Clazz2
        Error:(16, 50) java: incompatible types: <anonymous Test2.Foo<Clazz2.A>> cannot be converted to Test2.FooNest

        The second message seem not to correspond to the code.

        The error doesn't occur, provided assignment is removed, that is resulting in following code:

                new FooNest<>(clazz.a, new Foo<>() {});

              sadayapalam Srikanth Adayapalam (Inactive)
              grakov Georgiy Rakov (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: