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

Translation for instanceof is not triggered when patterns are not used in the compilation unit

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 24
    • None
    • tools
    • None
    • b27

      When instanceof as a type comparison operator is used without any patterns in the current compilation unit, desugaring is skipped.

      Sample 1:

      import java.util.List;

      public class Test {
            
          public static void main(String argv[]) {
                  List<Short> ls = List.of((short) 42);
                  System.out.println(ls.get(0) instanceof int);
                  //System.out.println(ls.get(0) instanceof int p);       
          }
      }

      output:
      false

      Sample 2:

      import java.util.List;

      public class Test {
            
          public static void main(String argv[]) {
                  List<Short> ls = List.of((short) 42);
                  System.out.println(ls.get(0) instanceof int);
                  System.out.println(ls.get(0) instanceof int p);       
          }
      }

      Output:
      true
      true

            abimpoudis Angelos Bimpoudis
            abimpoudis Angelos Bimpoudis
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: