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

Pattern type X is a subtype of expression type Y message is incorrect

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 16, 17
    • Fix Version/s: 17
    • Component/s: tools
    • Labels:
      None
    • Subcomponent:
    • Introduced In Build:
      b24
    • Introduced In Version:
      16
    • Resolved In Build:
      b08

      Description

      E.g. compile the following code:

      public class Test {
        void test(String s) {
          if(s instanceof Object obj) {}
        }
      }

      >"C:\Program Files\Java\jdk-17\bin\javac.exe" --enable-preview --release=17 Test.java
      Test.java:3: error: pattern type Object is a subtype of expression type String
          if(s instanceof Object obj) {}
               ^
      1 error

      Clearly, Object is not a subtype of String. It's vice versa: String is subtype of Object.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              vromero Vicente Arturo Romero Zaldivar
              Reporter:
              tvaleev Tagir Valeev
              Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: