title: List forEach with method reference explanation
body: <p>I have been learning java for past few months and just started to get into lambda functions. I recently switched my IDE and noticed a warning saying "Can be replaced with method reference" on codes like this.</p>
  
  <pre><code>   List&lt;Integer&gt; intList = new ArrayList&lt;&gt;();
          intList.add(1);
          intList.add(2);
          intList.add(3);
  
          intList.forEach(num -&gt; doSomething(num));
  
      voiddoSomething(int num) {
          System.out.println("Number is: " + num);
      }
  </code></pre>
  
  <p>After some digging, I realized that instead of the line</p>
  
  <pre><code> intList.forEach(num -&gt; doSomething(num));
  </code></pre>
  
  <p>I can just use</p>
  
  <pre><code> intList.forEach(this::doSomething);
  </code></pre>
  
  <p>This is just amazing. A few days ago I did not even knew about lambdas and was using for loops to do operations like this. Now I replaced my for loops with lambdas and even better, I can replace my lambdas with method references. The problem is that I don't really understand how all this works internally. Can anyone please explain or provide a good resource explaining how the doSomething function is called and the argument is passed to it when we use method reference?</p>