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

single static import of members with the same simple name allowed

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description



      Name: izR10247 Date: 09/24/2003



      The Static import specification (JSR 201, draft of 08 Sep, 2003)
      Section "Full Proposal" reads:"
      If two single-static-import declarations in the same compilation unit
      attempt to import members with the same simple name, then a compile-time
      error occurs, unless the two members are the same member of the same
      type, in which case the duplicate declaration is ignored."

      However, a compile-time error does not occur for the described situation
      when current 1.5.0-b20 implementation of J2SE is used.
       
      To reproduce this bug please run the following test
      using Make.sh shell script:
      --------------- A.java source begin -----------------
      package p1;

      public class A {

          public static int f = 10;
          public static int m() {
              return f;
          }

          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 -----------------
      --------------- B.java source begin -----------------
      package p2;

      public class B {

          public static int f = 10;
          public static int m() {
              return f;
          }

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

          public static interface i {
              public int f = 4;
          }
      }
      --------------- B.java source end -----------------
      --------------- Test.java begin -----------------
      import static p1.A.a.m;
      import static p2.B.a.m;

      public class Test {

          public static void main(String argv[]) {

              System.out.println("m=" + m());
              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 B.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
      m=5
      --------------- Make.sh output end ----------------

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

        Attachments

          Activity

            People

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

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: