title: Serialization of a lambda after its creation
body: <p>I can <a href="https://stackoverflow.com/questions/22807912/how-to-serialize-a-lambda">serialize a lambda</a> with the following syntax:</p>
  
  <pre><code>Runnable r = (Runnable &amp; Serializable) () -&gt; System.out.println("");
  try (ObjectOutput oo = new ObjectOutputStream(new ByteArrayOutputStream())) {
    oo.writeObject(r);
  }
  </code></pre>
  
  <p>However if I receive the lambda from a client code and it has not been cast appropriately, I can't serialize it.</p>
  
  <p><strong>How can I serialize <code>r</code> below without changing its definition:</strong></p>
  
  <pre><code>Runnable r = () -&gt; System.out.println("");
  </code></pre>
  
  <hr>
  
  <p>I have tried to serialize a "derived" object:</p>
  
  <pre><code>Runnable r1 = (Runnable &amp; Serializable) r::run;
  Runnable r2 = (Runnable &amp; Serializable) () -&gt; r.run();
  </code></pre>
  
  <p>but in each case, <code>oo.writeObject(rxxx);</code> fails with a <code>NotSerializableException</code>.</p>