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

Compilation error thrown while doing a boxing conversion on selector expression

XMLWordPrintable

    • b27
    • Verified

      The below code should compile successfully.

      class PatternTest {
          public static void main(String[] args) {

              int selExpr = 1;
              int retval = switch (selExpr) {
                  case Integer p -> 6;
                  default -> 1;
              };
              System.out.println(retval);
          }
      }

      However, the compilation throws error with JDK 18 b25:

      jdk-18/bin/javac --enable-preview -source 18 PatternTest.java
      PatternTest.java:6: error: bad operand type int for unary operator '<*nullchk*>'
              int retval = switch (selExpr) {
                                  ^
      Note: PatternTest.java uses preview features of Java SE 18.

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

              Created:
              Updated:
              Resolved: