Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There is no way to do this. The JLS says, in <a href="http://java.sun.com/docs/books/jls/third_edition/html/execution.html#12.4.1" rel="noreferrer">§12.4.1 When Initialization Occurs</a> (emphasis mine):</p> <blockquote> <p>Initialization of a class consists of executing its static initializers and the initializers for static fields declared in the class. [...]</p> <p><strong>A class or interface type T will be initialized immediately before the first occurrence of any one of the following</strong>:</p> <ul> <li>T is a class and an instance of T is created.</li> <li>T is a class and a static method declared by T is invoked.</li> <li>A static field declared by T is assigned.</li> <li>A static field declared by T is used and the field is not a constant variable (§4.12.4).</li> <li>T is a top-level class, and an assert statement (§14.10) lexically nested within T is executed. </li> </ul> <p>Invocation of certain reflective methods in class Class and in package java.lang.reflect also causes class or interface initialization. <strong>A class or interface will not be initialized under any other circumstance</strong>.</p> </blockquote> <p>A Java implementation which initialized classes as soon as they were loaded would violate the JLS.</p> <p>Although what you could do would be to use the JVM <a href="http://docs.oracle.com/javase/6/docs/api/java/lang/instrument/package-summary.html" rel="noreferrer">instrumentation API</a> to write a <a href="http://docs.oracle.com/javase/6/docs/api/java/lang/instrument/ClassFileTransformer.html" rel="noreferrer">ClassFileTransformer</a> which added a static block to every class which explicitly initialized its referenced classes (via Class.forName, probably). As soon as one class gets initialized, all the classes reachable from it will be initialized. That might give you the result you're after. It's quite a lot of work, though!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload