title: How does java differentiate Callable and Runnable in a Lambda?
body: <p>I got this little code to test out <code>Callable</code>. However, I find it pretty confusing how the Compiler could know if the Lambda is for the Interface Callable or Runnable since both don't have any parameter in their function. </p>
  
  <p>IntelliJ, however, shows that the Lambda employs the code for a Callable.</p>
  
  <pre><code>public class App {
      public static void main(String[] args) throws InterruptedException {
          ExecutorService executorService = Executors.newCachedThreadPool();
          executorService.submit(() -&gt;{
              System.out.println("Starting");
              int n = new Random().nextInt(4000);
              try {
                  Thread.sleep(n);
              } catch (InterruptedException e) {
                  e.printStackTrace();
              }finally {
                  System.out.println("Finished");
              }
              return n;
          });
          executorService.shutdown();
          executorService.awaitTermination(1, TimeUnit.MINUTES );
      }
  }
  </code></pre>