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

Qualified new of static inner class can generate incorrect code

XMLWordPrintable

    • x86, sparc
    • solaris_2.6, windows_95, windows_nt



      Name: tb29552 Date: 06/18/98


      /*
       * The output from the following code should be "enclosing
       * x is 10 \n y is 9". The code works if using the
       * tradition class initialization method, but fails if
       * using short-handed static inner class initialization
       * method. The output from the latter approach is
       * "enclosing x is 10 \n y is 0". The initialization
       * fails.
       *
       * The same problem is found in Symantec JIT compiler
       * version "JIT 210.054 JD 1.1.2" and "HP-UX Java
       * B.01.13.04".
       */
      public class OuterOne {
        static int x=10;
        static public class InnerOne {
          int y=9;
          public void innerMethod() {
            System.out.println("enclosing x is " + x);
            System.out.println("y is " + y);
          }
        }

        public void outerMethod() {
          System.out.println("x is " + x);
        }

        public static void main(String args[]) {
          // short-hand inner class initialization method
          OuterOne.InnerOne i1 = new OuterOne().new InnerOne();
          i1.innerMethod();

          // traditional method
          OuterOne o = new OuterOne();
          InnerOne i2 = o.new InnerOne();
          i2.innerMethod();
        }
      }

      (Review ID: 30802)
      ======================================================================

            tturnidgsunw Todd Turnidge (Inactive)
            tbell Tim Bell
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: