title: Implicit conversion to Runnable?
body: <p>As an exercise, I tried to create an implicit conversion that would accept a function and produce a <code>Runnable</code>. That way you could call Java methods that accept <code>Runnable</code> objects and use them like closures.</p>
  
  <p>The implicit conversion is easy enough:</p>
  
  <pre><code>    implicit def funToRunnable(fun : Unit) = new Runnable() { def run = fun }
  </code></pre>
  
  <p>However I don't know how to call it. How do you pass in a no-arg function that returns Unit, without having it be evaluated at once? For example, I'd like the following to print "12" but instead it prints "21" because <code>print("2")</code> is evaluated at once.</p>
  
  <pre><code>    var savedFun : Runnable = null
      def save(r : Runnable) = { savedFun = r }
  
      save(print("2"))
      print("1")
      savedFun.run()
  </code></pre>
  
  <p>How do I tell the compiler to treat <code>print("2")</code> as the body of a function, not something to be evaluated at once? Some possibilities I tried, such as </p>
  
  <pre><code>    save(() =&gt; print("2"))
  </code></pre>
  
  <p>or</p>
  
  <pre><code>    save(=&gt; print("2"))
  </code></pre>
  
  <p>are not legal syntax.</p>