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

Cannot parse switch expressions after type cast

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 13
    • 12, 13
    • tools
    • None
    • b22

      Consider this code:
      ---
      public class SE {
           private void t(Integer i) {
               String s = (String) switch (i) { default -> null; };
           }
      }
      ---

      Compiling this code leads to:
      ---
      $ javac --enable-preview --source 13 SE.java
      SE.java:3: error: ';' expected
               String s = (String) switch (i) { default -> null; };
                                  ^
      SE.java:3: error: not a statement
               String s = (String) switch (i) { default -> null; };
                                                           ^
      Note: SE.java uses preview language features.
      Note: Recompile with -Xlint:preview for details.
      2 errors
      ---

            jlahoda Jan Lahoda
            jlahoda Jan Lahoda
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: