title: Java dynamic adapter
body: <p>I'm using some Java code which produces the following interfaces. This code is non-modifiable.</p>
  
  <pre><code>interface A1 {
      public void run();
  }
  
  interface A2 {
      public void run();
  }
  
  ...
  
  interface A24 {
      public void run();
  }
  </code></pre>
  
  <p>I'm having a class cast error with the following code. How would I dynamically build an adapter to my interface?</p>
  
  <pre><code>interface ARunnable {
      public void run();
  }
  
  public void someMethod() {
      // getARunnables() returns a list of A1, A2, ... A24
      List&lt;ARunnable&gt; runnables = (List&lt;ARunnable&gt;)getARunnables(); 
  
      for (ARunnable a : runnables) {
          a.run();
      }
  }
  </code></pre>