title: Can you have a multiple-type variable declaration in Java?
body: <p>I have multiple interfaces and a class that implements all of them. I want to call all the methods defined in these interfaces on an instance of the implementing class, but I don't want to declare the variable as of the class type so that I'm still programming to interfaces.</p>
  
  <p>It seems that I have either to:</p>
  
  <ol>
  <li>Cast the object from one interface type to another to call the appropriate methods.</li>
  <li>Create a union interface which extends the others and declare a variable of that type.</li>
  </ol>
  
  <p>I would prefer not to do either of these because 1 is not type-safe and 2 can mean you quickly end up with a lot of 'union' interfaces which add nothing in themselves. Is it possible to have something like:</p>
  
  <pre><code>public interface A {
      public void doThis();
  }
  
  public interface B {
      public void doThat();
  }
  
  public class C implements A, B {
      public void doThis(){;}
      public void doThat(){;}
  }
  
  
  //Fake calling code:
  public void go() {
      A,B dualTypedInstance = new C(); //
      dualTypedInstance.doThis();
      dualTypedInstance.doThat();
  
  }
  </code></pre>
  
  <p>It really seems like this should be possible. Thanks.</p>