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

compiler error in casting class literal for primitive type

XMLWordPrintable

    • generic
    • generic



      Name: laC46010 Date: 02/14/99



      javac (1.1.x, 1.2fcs, 1.2.2) fails to compile cast expression with
      class literal for any primitive type. If the class literal gets
      parenthesized, compilation succeeds.

      Test example and diagnostics follow:
      -------------------------------------------------------
      novo35% cat test.java
      class test {
          static Class c1 = (Class) Object.class; // Ok
          static Class c2 = (Class) (int.class); // Ok
          static Class c3 = (Class) int.class; // Fail
      }

      novo35% java -version
      java version "1.2.2"
      Classic VM (build JDK-1.2.2-E, green threads, sunwjit)
      novo35% javac test.java
      test.java:4: ';' expected.
          static Class c3 = (Class) int.class; // Fail
                                   ^
      test.java:4: Identifier expected.
          static Class c3 = (Class) int.class; // Fail
                                        ^
      test.java:4: Identifier expected.
          static Class c3 = (Class) int.class; // Fail
                                              ^
      3 errors

      -------------------------------------------------------

      ======================================================================

            iris Iris Clark
            leosunw Leo Leo (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: