title: In Java, can a final field be initialized from a constructor helper?
body: <p>I have a final non-static member:</p>
  
  <pre><code>private final HashMap&lt;String,String&gt; myMap;
  </code></pre>
  
  <p>I would like to initialize it using a method called by the constructor. Since myMap is final, my "helper" method is unable to initialize it directly. Of course I have options:</p>
  
  <p>I could implement the myMap initialization code directly in the constructor.</p>
  
  <pre><code>MyConstructor (String someThingNecessary)
  {
      myMap = new HashMap&lt;String,String&gt;();
  
      myMap.put("blah","blahblah");
      // etc...
  
      // other initialization stuff unrelated to myMap
  }
  </code></pre>
  
  <p>I could have my helper method build the HashMap, return it to the constructor, and have the constructor then assign the object to myMap.</p>
  
  <pre><code>MyConstructor (String someThingNecessary)
  {
      myMap = InitializeMyMap(someThingNecessary);
  
      // other initialization stuff unrelated to myMap
  }
  
  private HashMap&lt;String,String&gt; InitializeMyMap(String someThingNecessary)
  {
      HashMap&lt;String,String&gt; initializedMap = new HashMap&lt;String,String&gt;();
  
      initializedMap.put("blah","blahblah");
      // etc...
  
      return initializedMap;
  }
  </code></pre>
  
  <p>Method #2 is fine, however, I'm wondering if there's some way I could allow the helper method to directly manipulate myMap. Perhaps a modifier that indicates it can only be called by the constructor?</p>
  
  <pre><code>MyConstructor (String someThingNecessary)
  {
      InitializeMyMap(someThingNecessary);
  
      // other initialization stuff unrelated to myMap
  }
  
  
  // helper doesn't work since it can't modify a final member
  private void InitializeMyMap(String someThingNecessary)
  {
      myMap = new HashMap&lt;String,String&gt;();
  
      myMap.put("blah","blahblah");
      // etc...
  }
  </code></pre>