title: How to use dependency injected fields for a static final field initialization in guice?
body: <p>I have a field in a class that stores the map of objects which are injected into the class. How to populate this field?</p>
  
  <p>This field will be primarily used for lookup and therefore qualifies to be a static final variable (Right?) ?</p>
  
  <p>Example : </p>
  
  <pre><code>mapOfObjects.put("foo",x);
  mapOfObjects.put("bar",y);
  </code></pre>
  
  <p>Sample Code</p>
  
  <pre><code>public class A {
      private ClassX x;
      private ClassY y;
  
      private final Map&lt;String, Object&gt; mapOfObjects = new HashMap&lt;&gt;();
  
      public void someMethod() {
          Object obj = mapOfObjects.get("x");
          //do something fancy with obj
      }
  
      @Inject
      public void setX(ClassX x) {
          this.x = x;
      }
  
      @Inject
      public void setY(ClassY y) {
          this.y = y;
      }
  }
  </code></pre>
  
  <ol>
  <li>Can the map construction be done in a static block? Is this method ugly?</li>
  <li>What happens first - dependency injection or static block of code?</li>
  <li>What is the best method so that this class is also testable.</li>
  </ol>
  
  <p>Thank you.</p>