title: How to reference a generic return type with multiple bounds
body: <p>I have recently seen that one can declare a return type that is also bounded by an interface. Consider the following class and interface:</p>
  
  <pre><code>public class Foo {
      public String getFoo() { ... }
  }
  
  public interface Bar {
      public void setBar(String bar);
  }
  </code></pre>
  
  <p>I can declare a return type like this:</p>
  
  <pre><code>public class FooBar {
      public static &lt;T extends Foo &amp; Bar&gt; T getFooBar() {
          //some implementation that returns a Foo object,
          //which is forced to implement Bar
      }
  }
  </code></pre>
  
  <p>If I call that method from somewhere, my IDE is telling me that the return type has the method <code>String getFoo()</code> as well as <code>setBar(String)</code>, but only If I point a dot behind the <em>Function</em> like this:</p>
  
  <pre><code>FooBar.getFooBar(). // here the IDE is showing the available methods.
  </code></pre>
  
  <p>Is there a way to get a reference to such an Object? I mean, if I would do something like this:</p>
  
  <pre><code>//bar only has the method setBar(String)
  Bar bar = FooBar.getFooBar();
  //foo only has the getFoo():String method
  Foo foo = FooBar.getFooBar();
  </code></pre>
  
  <p>I would like to have a reference like this (pseudo code):</p>
  
  <pre><code>&lt;T extents Foo &amp; Bar&gt; fooBar = FooBar.getFooBar();
  //or maybe
  $1Bar bar = FooBar.getFooBar();
  //or else maybe
  Foo&amp;Bar bar = FooBar.getFooBar();
  </code></pre>
  
  <p>Is this possible somehow in Java, or am I only able to declare return types like this? I think Java has to type it also, somehow. I'd prefer not to resort to a wrapper like this, as it feels like cheating:</p>
  
  <pre><code>public class FooBarWrapper&lt;T extends Foo&amp;Bar&gt; extends Foo implements Bar {
      public T foobar;
  
      public TestClass(T val){
          foobar = val;
      }
  
  
      @Override
      public void setBar(String bar) {
          foobar.setBar(bar);
      }
  
      @Override
      public String getFoo() {
          return foobar.getFoo();
      }
  }
  </code></pre>
  
  <p>Did Java really invent such a nice feature, but forget that one would like to have a reference to it?</p>