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

restrictions on bound of a type variable

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: P4 P4
    • None
    • 5.0
    • specification
    • x86
    • windows_xp



      Name: rmT116609 Date: 07/31/2003


      FULL PRODUCT VERSION :
      java version "1.4.2"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-b28)
      Java HotSpot(TM) Client VM (build 1.4.2-b28, mixed mode)

      FULL OS VERSION :
      Windows XP

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      generic prototype compiler 2.2-ea

      A DESCRIPTION OF THE PROBLEM :
      The generics prototype compiler version 2.2-ea places undue restrictions on the bounds of a type variable. From the error message I conclude that at most one type variable can appear in the bounds list of another type variable.

      I do not see that this behavior is what the specification specifies. The specification does not impose any such restriction, neither in the syntax productions nor any place in the specification of the semantics of bounds.



      package generics;

      public class TypeVariablesInBounds {


      public static <S, T extends Comparable<S>, R extends S & T>
      R max(T arg1, S arg2) {
      return (R)((arg1.compareTo(arg2)>0)?arg1:arg2);
      }

      public static <T extends Comparable<S>, S, R extends S & Comparable<S>>
      R max(T arg1, S arg2) {
      return (R)((arg1.compareTo(arg2)>0)?arg1:arg2);
      }

      public static <T extends Comparable<S>, S, R extends Comparable<S>>
      R max(T arg1, S arg2) {
      return (R)((arg1.compareTo(arg2)>0)?arg1:arg2);
      }

      public static void main(String[] args) {
      }
      }

      error messages:

      TypeVariablesInBounds.java:6: a type variable may not be followed by other bounds
      public static <S, T extends Comparable<S>, R extends S & T>
                                                                         ^
      TypeVariablesInBounds.java:11: a type variable may not be followed by other bounds
      public static <T extends Comparable<S>, S, R extends S & Comparable<S>>

                                                                                   ^


      In the first case the restriction would make sense if T resolves to a class type, but it need not be rejected upfront.

      In the second case I do not see any reason for the restriction.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      compile source code

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      error free compilation
      ACTUAL -
      compile-time error messages

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      TypeVariablesInBounds.java:6: a type variable may not be followed by other bounds
      public static <S, T extends Comparable<S>, R extends S & T>
                                                                         ^
      TypeVariablesInBounds.java:11: a type variable may not be followed by other bounds
      public static <T extends Comparable<S>, S, R extends S & Comparable<S>>
                                                                                   ^
      TypeVariablesInBounds.java:8: inconvertible types
      found : java.lang.Object
      required: R
      return (R)((arg1.compareTo(arg2)>0)?arg1:arg2);
                                ^
      TypeVariablesInBounds.java:13: inconvertible types
      found : java.lang.Object
      required: R
      return (R)((arg1.compareTo(arg2)>0)?arg1:arg2);
                                ^
      4 errors


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package generics;

      public class TypeVariablesInBounds {


      public static <S, T extends Comparable<S>, R extends S & T>
      R max(T arg1, S arg2) {
      return (R)((arg1.compareTo(arg2)>0)?arg1:arg2);
      }

      public static <T extends Comparable<S>, S, R extends S & Comparable<S>>
      R max(T arg1, S arg2) {
      return (R)((arg1.compareTo(arg2)>0)?arg1:arg2);
      }

      public static <T extends Comparable<S>, S, R extends Comparable<S>>
      R max(T arg1, S arg2) {
      return (R)((arg1.compareTo(arg2)>0)?arg1:arg2);
      }

      public static void main(String[] args) {
      }
      }

      ---------- END SOURCE ----------
      (Incident Review ID: 193198)
      ======================================================================

            abuckley Alex Buckley
            rmandalasunw Ranjith Mandala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: