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

generics: problem with method type parameter used in static context

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4
    • 1.4.2
    • 5.0
    • tools
    • mantis
    • generic
    • solaris_8

    Description

      Compilation of the joined source java file, shows problems when using a
      type parameter
      in a static constant declaration.
      I expected the compiler to reject such declarations.


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

      class Cl1<T> implements If<T>
      {
      static 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 C1<T>
      {
      static 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: