title: How to change the type of a function reference?
body: <p>Java8 lets me use a method declaration as implementation of any of my interfaces, as long as it only contains one method.</p>
  
  <p>However once it is defined, the type cannot be changed.</p>
  
  <p>My code:</p>
  
  <pre><code>import java.util.function.IntConsumer;
  
  public class A {
  
      interface MyConsumer {
          void doSomething(int i);
      }
  
      public static void main(String[] args) {
          IntConsumer i = A::consume;
          MyConsumer i2 = A::consume;
  
          IntConsumer i3 = (IntConsumer) i2; // ClassCastException
          MyConsumer i4 = (MyConsumer) i; // ClassCastException
  
          IntConsumer i5 = i2; // does not compile
          MyConsumer i6 = i; // does not compile
  
          IntConsumer i7 = i2::doSomething; // workaround, as suggested by @Eran http://stackoverflow.com/a/35846001/476791
          MyConsumer i8 = i::accept;
  
          Object i9 = A::consume; // does not compile
          Object i10 = (IntConsumer) A::consume; // works
          Object i11 = (MyConsumer) A::consume; // works
          Object i12 = (MyConsumer) (IntConsumer) A::consume; // does not work
      }
  
      static void consume(int i) {
          System.out.println(i);
      }
  }
  </code></pre>
  
  <p>Note: if you <em>inline</em> some of the variables, then some of the non-working examples suddenly start to work.</p>
  
  <p>My thoughts in detail:</p>
  
  <ol>
  <li>if <code>IntConsumer i = A::consume</code> is valid, then <code>A::consume</code> has to <code>implement IntConsumer</code></li>
  <li>if <code>MyConsumer i2 = A::consume</code> is valid, then <code>A::consume</code> has to <code>implement MyConsumer</code></li>
  <li>if <code>A::consume</code> implements <strong>both</strong>, <code>IntConsumer</code> and <code>MyConsumer</code>, then casting should be possible</li>
  </ol>
  
  <p>Is there another way to "cast" or "change" the type of the consumer afterwards?</p>