title: Is method reference caching a good idea in Java 8?
body: <p>Consider I have code like the following:</p>
  
  <pre><code>class Foo {
  
     Y func(X x) {...} 
  
     void doSomethingWithAFunc(Function&lt;X,Y&gt; f){...}
  
     void hotFunction(){
          doSomethingWithAFunc(this::func);
     }
  
  }
  </code></pre>
  
  <p>Suppose that <code>hotFunction</code> is called very often. Would it then be advisable to cache <code>this::func</code>, maybe like this:</p>
  
  <pre><code>class Foo {
       Function&lt;X,Y&gt; f = this::func;
       ...
       void hotFunction(){
          doSomethingWithAFunc(f);
       }
  }
  </code></pre>
  
  <p>As far as my understanding of java method references goes, the Virtual Machine creates an object of an anonymous class when a method reference is used. Thus, caching the reference would create that object only once while the first approach creates it on each function call. Is this correct?</p>
  
  <p>Should method references that appear at hot positions in the code be cached or is the VM able to optimize this and make the caching superfluous? Is there a general best practice about this or is this highly VM-implemenation specific whether such caching is of any use?</p>