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

    • Bug
    • Resolution: Fixed
    • P4
    • 17
    • 16, 17
    • tools
    • None
    • b24
    • 16
    • 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

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

              Dates

                Created:
                Updated:
                Resolved: