title: Unable to deserialize lambda
body: <p>Just as a small project, I've been trying to make a wee thing that reads serialized lambdas (locally or from an FTP) and invokes their run functions as part of a test to experiment with file associations in Windows (i.e. opening certain file types opens them with a certain program) and whatnot, but no matter what I try, it never seems to properly deserialize.</p>
  
  <p>The lambda was declared like so</p>
  
  <pre><code>Runnable r = (Runnable &amp; Serializable) () -&gt; {
      // blah blah
      // made sure not to capture anything
  };
  </code></pre>
  
  <p>and serialized using a FileOutputStream wrapped by a[n optional] BufferedOutputStream wrapped by an ObjectOutputStream without issue. However, when deserialized [in a different project], it fails, saying that it could not find the enclosing class that contained the code for serializing it. I've tried various things like wrapping them in a serializable class (w/serialVersionUID = 0L for testing purposes) or defining a an interface that extends Runnable and Serializable, but to no avail.</p>
  
  <p>Yes, I am aware that serializing lambdas isn't really good practice (or so we're told), but I'm not sure how to go about turning functions and subroutines into something I can store as a file or in an FTP. If this isn't even the right way at all, do tell.</p>
  
  <p>Oh, I'm using Eclipse Luna of whatever the latest version is.</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>Deserialized like so</p>
  
  <pre><code>File f = new File(somePath);
  FileInputStream fish = new FileInputStream(f);
  BufferedInputStream bos = new BufferedInputStream(fish); // not really necessary
  ObjectInputStream ois = new ObjectInputStream(bos);
  Runnable r = (Runnable) ois.readObject();
  ois.close();
  r.run();
  </code></pre>