title: Change flow of static call (Java)
body: <p>I have many instances of</p>
  
  <pre><code>Foo.a()
  </code></pre>
  
  <p>but now I want to split up calls to a() based on certain criteria. If possible I would like to keep the Foo.a() calls unchanged. Instead, perhaps Foo could become a factory that manages the flow and FooA and FooB could extend Foo. For example, in Foo:</p>
  
  <pre><code>private static Class&lt;?&gt; foo;
  
  static {
       if (certain_criteria) {
          foo = SomeUtil.getClass("FooA");
       } else  {
           foo = FooB.class;
       }
       Object obj = foo.newInstance();
       o = (Foo) obj;
   }
  ...
  public static void a() {
      o.a(); //And this should call either FooA.a() or FooB.a()
             //But a() should be accessed in a static way
  }
  </code></pre>
  
  <p>I can't make a() in Foo non-static because then I'll have to change the 100+ calls throughout the project to Foo.a(). Is there a way around this? Or a better way to handle the flow?</p>
  
  <p>I also tried to use foo to call a(), but that gives a compiler error because it is of type Class?>. If I change it to </p>
  
  <pre><code>Class&lt;Foo&gt; 
  </code></pre>
  
  <p>then I get</p>
  
  <pre><code>Type mismatch: cannot convert from Class&lt;FooB&gt; to Class&lt;Foo&gt;
  </code></pre>