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

Javac does not allow local class instance creation in an enclosing local class.

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      generic, sparc
    • OS:
      generic, solaris_7

      Description


      allan.jacobs@Eng 1997-10-27

      Javac may not allow a local class instance creation expression to
      occur in a block. The problem code occurs when this block is
      inside a method of an enclosing instance that is also a local, inner
      class.

      The source code is derived from Modena (2.2) test ciner062.

      algol% uname -a
      SunOS algol 5.6 Generic sun4u sparc SUNW,Ultra-1
      algol% java -fullversion
      java full version "1.1.8"
      algol% setenv CLASSPATH .
      algol% javac -d . X.java
      X.java:14: Class X. 1$Z not found in type declaration.
              return new Z().test();
                         ^
      1 error
      algol% cat X.java
      class X {
        int s=0;
        X() { s=0; }
        int test() {
          class Y { //enclosing class is X
           Y() { s=1; }
           int test() {
              class Z { // enclosing instance is Y
                Z() { new X().super(); }
                int test() { return s; }
              }
              // javac error message:
              // X.java:14: Class X. 1$Z not found in type declaration.
              return new Z().test();
            }
          }
          return new Y().test();
        }
        public static void main(String[] s) {
          X x=new X();
          System.out.println(x.test());
        }
      }

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              wmaddoxsunw William Maddox (Inactive)
              Reporter:
              ajacobssunw Allan Jacobs (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: