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

Using a class literal causes outermost class to be initialized early

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P5
    • 1.4.2
    • 1.4.0, 1.4.2
    • tools
    • mantis
    • generic, x86
    • solaris_7, windows_2000
    • Verified

    Description

      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

      Attachments

        Issue Links

          Activity

            People

              gafter Neal Gafter
              gafter Neal Gafter
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: