title: What is meant by lambda target type and target type context in Java?
body: <p>I'm reading a chapter on lambdas in Herbert Schildt's "Java: The Complete Reference" and there are quite a few references to "lambda target type" and "target type context":</p>
  
  <blockquote>
    <p>A functional interface defines the <strong>target type</strong> of a
    lambda expression. Here is a key point: a lambda expression can be used only
    in a context in which its <strong>target type</strong> is specified.</p>
  </blockquote>
  
  <p>Or:</p>
  
  <blockquote>
    <p>As mentioned earlier, a lambda expression is not executed on its own.
    Rather, it forms the implementation of the abstract method defined by the
    functional interface that specifies its <strong>target type</strong>. As a result, a lambda
    expression can be specified only in a context in which a <strong>target type</strong> is
    defined. One of these contexts is created when a lambda expression is
    assigned to a functional interface reference. Other <strong>target type contexts</strong>
    include variable initialization, return statements, and method arguments, to
    name a few.</p>
  </blockquote>
  
  <p>Yet another:</p>
  
  <blockquote>
    <p>The functional interface associated with a lambda expression can be generic. In
    this case, the <strong>target type</strong> of the lambda expression is determined, in part, by the type argument or arguments specified when a functional interface
    reference is declared.</p>
  </blockquote>
  
  <p>Can someone please help me understand what's meant by lambda target type?</p>
  
  <p>For instance, in <code>(int n) -&gt; n % 2 == 0</code> is <code>int</code> the lambda's target type?</p>
  
  <p>Or in:</p>
  
  <pre><code>interface MyInterface&lt;T&gt; {
      T func();
  }
  
  MyInterface&lt;String&gt; myInt = () -&gt; { return "123"; }
  </code></pre>
  
  <p>What is the lambda's target type? Is it <code>String</code> or <code>MyInterface&lt;String&gt;</code>? And what is the lambda's context here?</p>
  
  <p>I read several posts on SO on the topic but still cannot fully understand the notions.</p>
  
  <p>Thanks.</p>