Compiler always says "local classes must not extend sealed classes" even if class is anonymous

Vicente Romero vicente.romero at oracle.com
Tue Jun 9 15:17:04 UTC 2020


Hi Zheka,

Thanks for the report, I have created [1] to track it,

Vicente

[1] https://bugs.openjdk.java.net/browse/JDK-8247237

On 6/8/20 8:32 AM, Zheka Kozlov wrote:
> Hello!
>
> Compiling this program
>
> public class Main {
>      public static void main(String[] args) {
>          Shape shape = new Shape() {};
>      }
> }
>
> sealed interface Shape {
> }
>
> leads to an error:
>
> error: local classes must not extend sealed classes
>          Shape shape = new Shape() {};
>                                    ^
>
> But the class of `shape` is an anonymous class rather than a local class.
> By definition, a local class must have a name (JLS 14.3). I think the error
> message should say " anonymous classes must not extend sealed classes".
>
> Bith best regards, Zheka.



More information about the amber-dev mailing list