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

generics: type cast with instance of

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 5.0
    • 5.0
    • tools
    • b24
    • generic
    • solaris_9

      ^V/*
       * @test @(#)InstanceOf.java
       * @summary type comparison and type cast with instanceof
       * @compile InstanceOf.java
       */

      class InstanceOf<T>
      {
          static interface I1<T>
      {
      public T[] toArray();
          }
          static interface I2<T> extends I1<T>
      {
      public T[] toArray();
          }
          static interface I3<T> extends I2<T> { }
          InstanceOf()
      {
      I1<T> inv = null;
      I1<? extends T> cov = null;
      I1<? super T> con = null;
      boolean b;
      b = inv instanceof I3; // <<pass>>
      b = cov instanceof I3; // <<pass>> THIS FAILS
                      b con instanceof I3; // <<pass>>
          }
      }

      //InstanceOf.java:25: types InstanceOf.I1<? extends T> and InstanceOf.I3 are
      //incompatible; both define toArray(), but with different return type
      // b = cov instanceof I3; // <<pass>> <<todo: casts>>
                          ^

            gafter Neal Gafter (Inactive)
            ssides Steve Sides
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: