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

yield <primitive-type>.class not parsed correctly.

XMLWordPrintable

    • b02

        Consider:
        ---
        public class SwitchPrimitive {
             private void test(String s) {
                Class<?> c = switch (s) {
                     case "": yield int.class;
                     default: yield null;
                };
             }
        }
        ---

        This fails with:
        ---
        $ javac /tmp/SwitchPrimitive.java
        /tmp/SwitchPrimitive.java:4: error: not a statement
                     case "": yield int.class;
                              ^
        /tmp/SwitchPrimitive.java:4: error: ';' expected
                     case "": yield int.class;
                                   ^
        /tmp/SwitchPrimitive.java:4: error: not a statement
                     case "": yield int.class;
                                       ^
        3 errors
        ---

        while it should compile without errors.

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

                Created:
                Updated:
                Resolved: