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

Exception while using Anonymous class in switch expression

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      b23
    • Verification:
      Verified

      Description

      The below code leads to exception on execution.

      interface TestIntf {
          default int fun() {
              return 1;
          }
      }

      public class SwitchTest {

             public static void main(String[] args) {

                      int x = 10;
                      var y = switch(x) {
                                  case 0 -> new TestIntf(){};
                                  default -> new TestIntf(){};
                                  };

                                  System.out.println(y.fun());
                     }
      }

        Attachments

          Activity

            People

            • Assignee:
              jlahoda Jan Lahoda
              Reporter:
              vkhatri Vinod Khatri
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: