title: Will I incur a performance hit by using Class.forName(...) in a High Volume application?
body: <p>So here is what I am trying to do.  I have a web service that ultimately calls a simple dispatcher.  From the request the dispatcher instantiates a handler for that particular type of request.  All handlers implement the same interface.</p>
  
  <p>The problem I am struggling with is the best way for the dispatcher to instantiate the handler.</p>
  
  <p>The 2 solutions I have are:</p>
  
  <ol>
  <li><p>Use a Map with the key being the scenario (the same as on the request) and the value being the String to look up the class.</p>
  
  <pre><code>scenarios = new HashMap&lt;String, String&gt;();
  scenarios.put("A", "com.xyz.handlers.ScenarioAHandler");
  </code></pre>
  
  <p>Then do this:</p>
  
  <pre><code>handlerClass = Class.forName(scenarios.get(scenario));
  handler = (HandlerInterface) handlerClass.newInstance();
  </code></pre></li>
  <li><p>The other solution I have is to just use the class at the value.</p>
  
  <pre><code>scenarios = new HashMap&lt;String, Class&gt;();
  scenarios.put("A", ScenarioAHandler.class);
  </code></pre>
  
  <p>Then I could just do this to get an instance of the handler:</p>
  
  <pre><code>handler = (HandlerInterface) this.scenarios.get(scenario).newInstance();
  </code></pre></li>
  </ol>
  
  <p>Are either of these better than the the other or is there an even better solution I have not considered yet?</p>