title: can not initialize static final variable in try/catch
body: <p>I am trying to initialize a static final variable. However, this variable is initialized in a method which can throw exception, therefor, I need to have inside a try catch block.</p>
  
  <p>Even if I know that variable will be either initialized on try or on catch block, java compiler produces an error</p>
  
  <blockquote>
    <p>The final field a may already have been assigned</p>
  </blockquote>
  
  <p>This is my code:</p>
  
  <pre><code>public class TestClass {
  
    private static final String a;
  
    static {
      try {
        a = fn(); // ERROR
      } catch (Exception e) {
        a = null;
      }
    }
  
    private static String fn() throws Exception {
      throw new Exception("Forced exception to illustrate");
    }
  
  }
  </code></pre>
  
  <p>I tried another approach, declaring it as null directly, but it shows a similar error (In this case, it seems totally logic for me)</p>
  
  <blockquote>
    <p>The final field TestClass.a cannot be assigned</p>
  </blockquote>
  
  <pre><code>public class TestClass {
  
    private static final String a = null;
  
    static {
      try {
        a = fn(); // ERROR
      } catch (Exception e) {
      }
    }
  
    private static String fn() throws Exception {
      throw new Exception("Forced exception to illustrate");
    }
  
  }
  </code></pre>
  
  <p>Is there an elegant solution for this?</p>