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

compiler error in casting class literal for primitive type

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description



      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

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

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

        Attachments

          Activity

            People

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

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: