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

generics: problem with equivalence of generic types

    XMLWordPrintable

Details

    • tiger
    • generic
    • solaris_8

    Description

      The following program fails to compile using the generics compiler:

      /*
       * @test %W% %E%
       * @bug 4738171
       * @summary generics: problem with equivalence of generic types
       * @author gafter
       *
       * @compile/fail -source 1.5 T4738171.java
       */

      interface If<T> {
          final If<T> C0 = null;
      }

      class Cl1<T> implements If<T> {
          final If<T> C1 = null;
          If<T> f1() {
              If<T> c1 = C0; // incompatible types found: If<T> required: If<T>
              If<T> c2 = C1;
              return C0; // incompatible types found: If<T> required: If<T>
          }
      }

      class Cl2<T> extends Cl1<T> {
          final If<T> C2 = new Cl2<T>();
          // non-static class T cannot be referenced from a static context
          // but why can class T be referenced in the type declaration ?
          If<T> f2() {
              If<T> c1 = C0; // incompatible types found: If<T> required: If<T>
              If<T> c2 = C2;
              return C1; // incompatible types found: If<T> required: If<T>
          }
      }

      Attachments

        Activity

          People

            gafter Neal Gafter
            gafter Neal Gafter
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: