title: In Java, can we claim that lambda expressions are stored and is present in heap?
body: <pre><code>1. public interface MyComparator {
  2.    public boolean compare(int a1, int a2);
  3. }
  4. MyClass obj = new MyClass();
  5. MyComparator myComparator = (a1, a2) -&gt; return a1 &gt; a2;
  6. boolean result = myComparator.compare(2, 5);
  </code></pre>
  
  <p>In line number 4, obj is a reference which refers to object on the heap, which was constructed by invoking MyClass().
  In line number 5, myComparator is a reference which is referring to
  what is present on the other side of assignment operator, i.e a Lambda Expression. </p>
  
  <ul>
  <li><p>Is Lambda Expression an object? If yes, is it stored on the heap? Does it adhere to rules of Garbage Collector, which cleans up unreferenced objects or it behaves slightly different?</p></li>
  <li><p>If no, i.e if Lambda Expression is not an object and thereby assuming that it is not present in heap, then how myComparator (being a reference, assuming that it is present in stack) is able to refer to a lambda expression and we are able to invoke a method on it?</p></li>
  <li><p>In Java, arrays are stored on heap, Can we safely claim that below array is also stored on heap? Can we safely assume that 'code which could be run' is getting stored as objects on the heap?</p>
  
  <pre><code>FileFilter myFileFilter[] = new FileFilter[] { 
  f -&gt; f.exists(), f -&gt; f.canRead(), f -&gt; f.getName().startsWith("q") 
      }
  </code></pre></li>
  <li><p>If Lambda expressions can be treated as an object, can we serialize this object and transport to another JVM, allowing to send 'executable' code from one JVM to another JVM, at runtime? This would allow to 'accept' logic from a system A to execute that logic on system B. As an aside, it might become possible to distribute 'code' to other systems (similar to serializing a runnable thread and sending across)? Am I thinking in right path, please clarify whether these are possibilities which are already present. Thanks
  (Would be interested to see some implementation details )</p></li>
  </ul>