title: What purpose is served by the `SerializableFunction` interface defined in Vaadin 8 if we can simply pass a regular Lambda expression in its place?
body: <p><a href="https://vaadin.com/framework" rel="nofollow noreferrer">Vaadin 8</a> defines a <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/FunctionalInterface.html?is-external=true" rel="nofollow noreferrer">functional interface</a>, <a href="https://vaadin.com/download/release/8.4/8.4.5/docs/api/com/vaadin/server/SerializableFunction.html" rel="nofollow noreferrer"><code>SerializableFunction</code></a>.</p>
  
  <p>This interface appears in various places. For example, when defining a <a href="https://vaadin.com/download/release/8.4/8.4.5/docs/api/com/vaadin/data/Converter.html" rel="nofollow noreferrer"><code>Converter</code></a> for displaying non-textual types in a <a href="https://vaadin.com/download/release/8.4/8.4.5/docs/api/com/vaadin/ui/TextField.html" rel="nofollow noreferrer"><code>TextField</code></a> such as a <a href="https://docs.oracle.com/javase/10/docs/api/java/util/UUID.html" rel="nofollow noreferrer"><code>UUID</code></a>.</p>
  
  <pre><code>Binder.BindingBuilder&lt;BEAN,TARGET&gt;::withConverter(SerializableFunction&lt;TARGET,NEWTARGET&gt; toModel, SerializableFunction&lt;NEWTARGET,TARGET&gt; toPresentation)
  </code></pre>
  
  <p>See <a href="https://vaadin.com/download/release/8.4/8.4.5/docs/api/com/vaadin/data/Binder.BindingBuilder.html#withConverter-com.vaadin.server.SerializableFunction-com.vaadin.server.SerializableFunction-" rel="nofollow noreferrer">class documentation</a>.</p>
  
  <p>Example usage:</p>
  
  <pre><code>binder
  .forField( this.idField )
  .withConverter( text -&gt; UUID.fromString( text ) , uuid -&gt; uuid.toString() )
  .bind(Panel :: getId , null );
  </code></pre>
  
  <p>Notice in that example that we simply pass a pair of simple <a href="https://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html" rel="nofollow noreferrer">Lambda expressions</a>:</p>
  
  <ul>
  <li><code>text -&gt; UUID.fromString( text )</code></li>
  <li><code>uuid -&gt; uuid.toString()</code></li>
  </ul>
  
  <p>My two questions:</p>
  
  <ul>
  <li>How is it that a regular Lambda can be slipped into a place where that specific type <code>SerializableFunction</code> is required? How did my Lambda expression qualify?</li>
  <li>Why did the Vaadin team bother defining the interface <code>SerializableFunction</code> if any plain old Lambda can fit in its place?</li>
  </ul>
  
  <p>My aim here is not so much about the particulars of Vaadin (though I am curious there too) as it is about the Java type system, Lambdas, and functional programming.</p>
  
  <p>I understand why Vaadin web apps need every object to be <a href="https://en.wikipedia.org/wiki/Serialization" rel="nofollow noreferrer">serializable</a>: In case at deployment the <a href="https://en.wikipedia.org/wiki/Web_container" rel="nofollow noreferrer">web container</a> chooses to move a user session between app servers. My question is not about the serializing aspect. My question is about the Java language type mechanics, and what good does it do to add an extra <a href="https://en.wikipedia.org/wiki/Interface_(computing)#Software_interfaces_in_object-oriented_languages" rel="nofollow noreferrer">interface</a> that requires no extra coding. </p>
  
  <hr>
  
  <p>I’ll not even ask what it means for a Lambda expression to be serializable as it makes my head hurt.</p>