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

javac refuses to compile InterfaceName.class, but fastjavac works

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 1.2.0
    • tools
    • None
    • generic
    • solaris_2.5.1

      Here is a bug (IMO) in all versions of javac. Note that fastjavac does not exhibit this problem, and javac on classes (vs. interfaces) works fine:


      class TestClass {
          static Class myClass = TestClass.class;
      }

      class TestClassSibling {
          static Class myClass = TestClass.class;
      }

      public interface TestInterface {
          // *see comments below
          //static public Class myClass = TestInterface.class;
      }

      class TestInterfaceSibling {
          static Class myClass = TestInterface.class;
      }

      /*
      NOTE: with this line of code "static public Class myClass = TestInterface.class;" in an interface, fastjavac compiles,
          and runs, fine.
          javac, however, barfs with the following output:

      javalite: ~kbern/tmp/uwe> javac TestInterface.java
      TestInterface.java:9: Interface methods can't be native, static, synchronized, final, private, or protected : java.lang.Class class$(java.lang.String)
      public interface TestInterface {
      ^
      TestInterface.java:11: Can't make static reference to method java.lang.Class class$(java.lang.String) in interface TestInterface.
      static public Class myClass = TestInterface.class;
      ^
      2 errors

      Stranger still is that if I comment out that line of code, javac compiles fine, even though the "TestInterfaceSibling"
      class has the same line of code... BUT, if move TestInterfaceSibling to its own file in the same dir (and make it
      "public"), then it too fails, with the same error. Again, in this case fastjavac has no problem, and the code
      runs fine.

      Note also that even if I make TestInterfaceSibling be an inner class of TestInterface, then the code in
      TestInterfaceSibling gives the same compiler error from javac (but not fastjavac).
      */

            dstoutamsunw David Stoutamire (Inactive)
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: