java 17: anonymous classes with diamonds
Srikanth
srikanth.adayapalam at oracle.com
Mon Jan 18 10:18:00 UTC 2021
Thanks for the problem report Anna.
It does look suspect and I have raised JDK-8259910 to follow up.
This problem dates back to jdk9 and is reproducible in all the major
releases from then on.
Srikanth
On 18/01/21 3:08 pm, Anna Kozlova wrote:
> Hi all,
>
> The following code doesn't compile with java 17 eap (java:
> foo.Boo.Nested is abstract; cannot be instantiated)
> ```
> public class Boo {
> static abstract class Nested<T> {
> protected Nested(Class<T> aAcceptedClass) { }
>
> }
> static class Outer<T> {
> protected Outer(final Nested<T> condition) { }
> }
>
> static final Outer<Boo> PATTERN =new Outer<>(new Nested<>(Boo.class) {}) {};
> }
> ```
> though the anonymous class is used.
>
> At the same time, if I remove the anonymous class from outer call, like
> `static final Outer<Boo> PATTERN = new Outer<>(new Nested<>(Boo.class)
> {});` the code would compile.
>
> If explicit types instead of diamonds are used, everything compiles
> fine as well.
>
> To me this looks like a bug in the compiler, could someone check this
> please?
>
> Thanks,
> Anna
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20210118/d201acb6/attachment-0001.htm>
More information about the compiler-dev
mailing list