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

compiler differs in compilation of similar tests

XMLWordPrintable

    • sparc
    • solaris_2.5.1



      Name: ngC57085 Date: 07/29/99



      Java compiler jdk1.3L successfully compiles test1.java file, and
      reports an error for test2.java

      --------------------------------- test1.java
      public class test1 {
      public static void main(String[] argv) {
      System.exit(run(argv));
      }

      public int i;
      static class NC extends test1 {
      int x = i;
      }

      public static int run(String argv[]) {
      return 0/*STATUS_PASSED*/;
      }
      }
      ---------------------------------------------
      --------------------------------- test2.java
      public class test2 {
      public static void main(String[] argv) {
      System.exit(run(argv));
      }

      int i;
      static class NC extends Y {
      int x = i;
      }

      public static int run(String argv[]) {
      return 0/*STATUS_PASSED*/;
      }
      }

      class Y {
      public int i;
      }
      ---------------------------------------------


      > java -version
      Warning: JIT compiler "sunwjit" not found. Will use interpreter.
      java version "1.3"
      Classic VM (build JDK-1.3-L, green threads, nojit)
      > javac -d . test1.java
      > java test1
      Warning: JIT compiler "sunwjit" not found. Will use interpreter.
      > echo $status
      0

      > javac -d . test2.java
      Warning: JIT compiler "sunwjit" not found. Will use interpreter.
      test2.java:8: i is inherited from Y.
      hides : variable
      location: test2
      An explicit 'this' qualifier must be used to select the desired instance.
      int x = i;
                              ^
      1 error
      >

      In the both tests the instance field i from class test1 (test2) is not
      accessible in nested top-level class NC. And in the both tests inhereted
      by class NC field i hides instance field i from outer class.
      But the results of compilation are different.


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

            wmaddoxsunw William Maddox (Inactive)
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: