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

Request Parameterized class ".class" Syntax

    Details

    • Type: Enhancement
    • Status: Closed
    • Priority: P4
    • Resolution: Duplicate
    • Affects Version/s: 5.0
    • Fix Version/s: None
    • Component/s: specification
    • Subcomponent:
    • CPU:
      x86
    • OS:
      windows_xp

      Description



      Name: rmT116609 Date: 05/03/2004


      A DESCRIPTION OF THE REQUEST :
      If A is a Type parameter, nothing in JSR-14 spec (spec 8) forbids me from using the expresson
          A.class
      But if I do so, it generates a compiler Error.

      JUSTIFICATION :
      Sometimes I need to return a Class object of a parameterized type. An example is a parameterized implementation of a TableModel. It uses a separate Column<ColType> instance for each column, but when writing the getColumnClass() method, the expression ColType.class generates this compiler error:

          cannot select from a type variable

      The .class member is sufficiently universal that it should be allowed.

      I don't see any other way to return the Class object of a parameterized type. (Any other way would satisfy me, but I won't always have an instance of the type, so I can't call its getClass() method.)

      Note: The class java.lang.Object has been modified so that the getClass()
        method returns an object of type
          Class<? extends Object>
        I don't know if this helps me get a class object of a parameterized type, but
        I found no reference to the ? symbol in the "specification of proposed
        language modifiations" in spec8.pdf. So I have no idea what it means.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The expression A.class should be legal, even when A is a parameterized type. It should resolve to the actual class invoked by the constructor.
      ACTUAL -
      The expression A.class generates a compiler error.

      ---------- BEGIN SOURCE ----------
      /* Compile this source code to see the error message. */
      public class ClassBug <CB>
      {
      private ClassBug()
      {
      }

      public Class getBugClass()
      {
      return CB.class;
      }
      }

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

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: