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

change compiler error: local classes must not extend sealed classes, if class is anonymous

    XMLWordPrintable

Details

    • Bug
    • Resolution: Won't Fix
    • P3
    • 15
    • 15
    • tools

    Description

      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".

      reported at amber-dev: https://mail.openjdk.java.net/pipermail/amber-dev/2020-June/006186.html

      Attachments

        Activity

          People

            vromero Vicente Arturo Romero Zaldivar
            vromero Vicente Arturo Romero Zaldivar
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: