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

JLS3 8.1.2 Sample code uses "<T implements ...>" instead of "<T extends ...>"

    XMLWordPrintable

Details

    • b96
    • generic
    • generic

    Description

      JLS 3 Chapter 8 "Classes", section 8.1.2 "Generic Classes and Type Parameters"
      provides the following example of mutually recursive type variable bounds:

      interface ConvertibleTo<T> {
         T convert();
      }
      class ReprChange<T implements ConvertibleTo<S>,
                       S implements ConvertibleTo<T>> {
         T t;
         void set(S s) { t = s.convert(); }
         S get() { return t.convert(); }
      }

      But keyword "implements" is not allowed within type parameter declaration. Accrding to the JLS3 syntax rules

      TypeParameter:
              Identifier [extends Bound]

      Due to that reason javac fails to compile the sample code.
      Replacing "implements" with "extends" solves the problem.

      Attachments

        Activity

          People

            iris Iris Clark
            asutchil Arkadiy Sutchilin (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: