title: Can you check if a static variable is loaded in java?
body: <p>I know we can use reflection to check if the class is loaded. However it would appear that although the class is loaded, the static variable I am looking at does not get loaded until I access it for the first time. The variable in question is a <code>WebDriver</code> in my <code>TestDriver</code> class.</p>
  
  <p>So, my problem is that I have a test details interface to enter in some test details before the execution of the test. When I press start test on this interface, the <code>WebDriver</code> opens and the tests are performed. However, when I don't press the start test button, and close the test details interface, the <code>ChromeDriver</code> is opened first and then closed; which is unnecessary. So if there was a way to check if the driver is initialized before calling <code>driver.quit()</code>, I can call <code>driver.quit()</code> if it is initialized and not if otherwise.</p>
  
  <p>Comment if you need me to clarify any details, I know I'm not great at asking questions.</p>
  
  <pre><code>@Override
  public void dispose(){
      try{
          Method m = ClassLoader.class.getDeclaredMethod("findLoadedClass", new Class[] {String.class});
          m.setAccessible(true);
          ClassLoader cl = ClassLoader.getSystemClassLoader();
          Object isclassloaded = m.invoke(cl, "testframework.TestDriver");
          //System.out.println(isclassloaded == null);
          if(isclassloaded != null){
              TestDriver.driver.quit();
          }
      } catch(Exception e){
          e.printStackTrace();
      }
      System.exit(0);
  }
  </code></pre>
  
  <p>TestDriver.java</p>
  
  <pre><code>public class TestDriver {
  
      public static WebDriver driver = new ChromeDriver();
  
      ...
  }
  </code></pre>