Using a class literal causes outermost class to be initialized early

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: P5
    • 1.4.2
    • Affects Version/s: 1.4.0, 1.4.2
    • Component/s: tools
    • mantis
    • generic, x86
    • solaris_7, windows_2000
    • Verified

      Using a class literal causes the outermost enclosing class to be initialized too early. Consider

      class A {
          static {
      System.out.println("You shouldn't see this.");
          }
          public static class B {
      B() {
      Object o = Main.class; // line N
      }
          };
      }

      class Main {
          public static void main(String[] args) {
      new A.B();
          }
      }

      The presence of line N causes the program to print "You shouldn't see this.". When that line is removed, that message is not printed.

      neal.gafter@Eng 2001-01-03

            Assignee:
            Neal Gafter (Inactive)
            Reporter:
            Neal Gafter (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: