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

generics: type cast with instance of

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 5.0
    • Fix Version/s: 5.0
    • Component/s: tools
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      b24
    • CPU:
      generic
    • OS:
      solaris_9

      Description

      ^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>>
                          ^

        Attachments

          Activity

            People

            • Assignee:
              gafter Neal Gafter
              Reporter:
              ssides Steve Sides
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: