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

Ill-defined order of initialization.

XMLWordPrintable

    • 1.2beta
    • x86, sparc
    • solaris_2.4, windows_nt
    • Not verified


      The following program yields "5, 6".
      class Lang {
          int i = m();
          int j = 0;
          Lang() {
      System.out.println(i + ", " + j);
          }
          int m() { j = 5; return j++; }
          static public void main(String args[]) {
      new Lang();
          }
      }

      However, the following program yields "5, 1".
      class Lang {
          int i = m();
          int j = 1;
          Lang() {
      System.out.println(i + ", " + j);
          }
          int m() { j = 5; return j++; }
          static public void main(String args[]) {
      new Lang();
          }
      }

            tturnidgsunw Todd Turnidge (Inactive)
            vssriniv Vijay Srinivasan (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: