title: How to force instantiation of static fields
body: <p>I was quite surprised of the output of the following code:</p>
  
  <p><strong>Country class</strong></p>
  
  <pre><code>public class Country {
  
      private static Map&lt;String, Country&gt; countries = new HashMap&lt;String, Country&gt;();
  
      private final String name;
  
      @SuppressWarnings("LeakingThisInConstructor")
      protected Country(String name) {
          this.name = name;
          register(this);
      }
  
      /** Get country by name */
      public static Country getCountry(String name) {
          return countries.get(name);
      }
  
      /** Register country into map */
      public static void register(Country country) {
          countries.put(country.name, country);
      }
  
      @Override
      public String toString() {
          return name;
      }
  
      /** Countries in Europe */
      public static class EuropeCountry extends Country {
  
          public static final EuropeCountry SPAIN = new EuropeCountry("Spain");
          public static final EuropeCountry FRANCE = new EuropeCountry("France");
  
          protected EuropeCountry(String name) {
              super(name);
          }
      }
  
  }
  </code></pre>
  
  <p><strong>Main method</strong></p>
  
  <pre><code>System.out.println(Country.getCountry("Spain"));
  </code></pre>
  
  <p><strong>Output</strong></p>
  
  <blockquote>
    <p>null</p>
  </blockquote>
  
  <p>Is there any clean way of forcing the class that extend Country to be loaded so the countries map contains all the Country instances?</p>