title: How to serialize a lambda in kotlin
body: <p>I am trying to serialize a lambda as in java 8 which is performed like this:</p>
  
  <p>Runnable r = (Runnable &amp; Serializable)() ->{doSomething();};</p>
  
  <p>but when it try the same thing in kotlin like this:</p>
  
  <p>val r = { doSomething() } as (Runnable , Serializable)</p>
  
  <p>i get a compile error of:</p>
  
  <p><a href="https://i.stack.imgur.com/d9QVR.png" rel="noreferrer"><img src="https://i.stack.imgur.com/d9QVR.png" alt="enter image description here"></a></p>
  
  <p>even if i try to paste the java code into kotlin file it will remove the serializable portion of the cast. therefore how to serialize lambda in kotlin ?</p>