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

static import of static interfaces and classes allowed

XMLWordPrintable

    • generic
    • generic



      Name: izR10247 Date: 09/24/2003



      Current 1.5.0-b20 implementation of J2SE allows
      to use single-static-import declaration for the static
      member which is nested class or interface. Such declaration
      should not be used since current Static Import specification (JSR
      201, draft of 08 Sep, 2003) does not state explicitly that nested
      static class or nested static interface can be imported from one
      compilation unit to another using single-static-import
      declaration. For the importing of nested static classes
      and nested static interfaces single-type-import-declaration
      should be used.

      Also section "Summary" of the draft contains the following:
      "The proposal is to introduce variants of the import statement into the
      JavaTM programming language so as to allow importation of static methods
      and fields in the manner that classes and interfaces can now be imported."

      Since importing of the static nested classes and interfaces
      is not allowed compile-time error should be reported.
       
      To reproduce this bug please run the following test
      using Make.sh script:
      --------------- A.java source begin -----------------
      package p;

      public class A {

          public static class a {
              public static int f = 4;
              public static int m() {
                  return 5;
              }
          }

          public static interface i {
              public int f = 4;
          }
      }

      --------------- A.java source end -----------------
      --------------- Test.java begin -----------------
      import static p.A.a;

      public class Test {

          public static void main(String argv[]) {

              System.exit(0);
          }
      }
      --------------- Test.java end -----------------
      --------------- Make.sh begin -----------------
      #!/bin/sh
      JDK=/export/ld25/java/dest/jdk1.5.0/solaris-sparc
      CLASSPATH=./:./p1:./p2
      uname -a
      echo 'Version:'
      $JDK/bin/java -version
      echo 'Compilation begin'
      $JDK/bin/javac -classpath $CLASSPATH -d . -source 1.5 A.java
      $JDK/bin/javac -classpath $CLASSPATH -d . -source 1.5 Test.java
      echo 'Compilation end'
      echo 'Running Test'
      $JDK/bin/java -classpath $CLASSPATH Test
      --------------- Make.sh end -----------------
      --------------- Make.sh output begin ----------------
      bash-2.03$ ./Make.sh
      SunOS novo148 5.8 Generic_108528-20 sun4u sparc SUNW,Ultra-80
      Version:
      java version "1.5.0-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b20)
      Java HotSpot(TM) Server VM (build 1.5.0-beta-b20, mixed mode)
      Compilation begin
      Compilation end
      Running Test
      --------------- Make.sh output end ----------------

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

            gbrachasunw Gilad Bracha (Inactive)
            garysunw Gary Gary (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: