title: Why Java-8 lambda need invokeDynamic byteCode to invoke an interface method
body: <p>Hi I am trying to understand the advantages of using Lambda expression, where I heard usage of the invokeDynamic byteCode by JVM to execute lambda expression will improve the performance compared to XXXX(Sorry I don't know, it might be an Anonymous inner class). </p>
  
  <p>My question is Why Lambda expressions need invokeDynamic byteCode. </p>
  
  <p>For example: </p>
  
  <pre><code>public class LambdaTest {
      public static void main(String[] args) {
          MathOperation addition = (int a, int b) -&gt; a + b;
          addition.operation(1, 2);
      }
  
      private static int operate(int a, int b, MathOperation operation){
          return operation.operation(a, b);
      }
  
      interface MathOperation {
         int operation(int a, int b);
      }
  }
  </code></pre>
  
  <p>where the lambda expression <code>(int a, int b) -&gt; a + b;</code> can be simply desugared into a static method like </p>
  
  <pre><code>   private static int lambda$1(int a, int b) {
         return a + b;
     }
  </code></pre>
  
  <p>which eventually can be invoked using <code>invokstatic</code> byteCode right?</p>
  
  <p>More questions: What is the dynamicity lambda expression trying to achieve, when all the argument type, returns type are defined during the compile time itself.</p>
  
  <p>For example: in the <code>lambda</code> expression <code>(int a, int b) -&gt; a + b;</code> everything(<code>argument type, return type</code>) got defined during the compile time itself right?</p>