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

getClass() doen't take into account that some classes are final

XMLWordPrintable

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

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

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      The JLS3 said that for a variable x of type X,
      X.getClass() return a type Class<? extends Erasure(X)>.

      I think this rule doesn't take into account of classes declared final.
      Indeed, final class could not have sub-classes, so

      "toto".getClass() could be typed Class<String>.

      This is a straighforward change because Class<? extends String> is a
      subtype of Class<String>

      PS: i have reported this as a bug but perhaps it's an RFE.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      try to compile the code

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      compile withour error
      ACTUAL -
      the compiler emit an erreor "incompatible types"

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      incompatible types :
      found : java.lang.Class<capture of ? extends java.lang.String>
      required: java.lang.Class<java.lang.String>

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      class Test {

      Class<String> clazz="toto".getClass();

      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Class<String> clazz=(Class<String>)"toto".getClass();
      ###@###.### 10/26/04 22:55 GMT

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: