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

Exception while using Anonymous class in switch expression

XMLWordPrintable

    • b23
    • Verified

      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());
                     }
      }

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

              Created:
              Updated:
              Resolved: