title: Kotlin: Use a lambda in place of a functional interface?
body: <p>In Java we can do this
  <code>Events.handler(Handshake.class, hs -&gt; out.println(hs));</code></p>
  
  <p>In Kotlin however I am trying to replicate the behavior to replace this:</p>
  
  <pre><code>Events.handler(Handshake::class, object : EventHandler&lt;Handshake&gt; {
      override fun handle(event: Handshake) {
          println(event.sent)
      }
  })
  </code></pre>
  
  <p>With a more convenient:</p>
  
  <p><code>Events.handler(Handshake::class, EventHandler&lt;Handshake&gt; { println(it.sent) })</code></p>
  
  <p>For some reason in reference to <code>EventHandler</code>:</p>
  
  <p><a href="https://i.stack.imgur.com/PYGGz.png" rel="noreferrer"><img src="https://i.stack.imgur.com/PYGGz.png" alt="enter image description here"></a></p>
  
  <p>More preferably however I'd like to use something even shorter like this:
  <code>Events.handler(Handshake::class, { println(it.sent) })</code></p>
  
  <p>Or use the advertised feature to use the method like this:
  <code>Events.handler(Handshake::class) { println(it.sent) }</code></p>
  
  <p>This is my <code>Events</code> object:</p>
  
  <pre><code>import java.util.*
  import kotlin.reflect.KClass
  
  object Events {
  
      private val map = HashMap&lt;Class&lt;*&gt;, Set&lt;EventHandler&lt;*&gt;&gt;&gt;()
  
      fun &lt;T : Any&gt; handler(eventType: KClass&lt;T&gt;, handler: EventHandler&lt;T&gt;) {
          handler(eventType.java, handler)
      }
  
      fun &lt;T&gt; handler(eventType: Class&lt;T&gt;, handler: EventHandler&lt;T&gt;) = handlers(eventType).add(handler)
  
      fun post(event: Any) = handlers(event.javaClass).forEach { it.handle(event) }
  
      operator fun plus(event: Any) = post(event)
  
      private fun &lt;T&gt; handlers(eventType: Class&lt;T&gt;): HashSet&lt;EventHandler&lt;T&gt;&gt; {
          var set = map[eventType]
          if (set == null) {
              set = HashSet&lt;EventHandler&lt;*&gt;&gt;()
              map.put(eventType, set)
          }
          return set as HashSet&lt;EventHandler&lt;T&gt;&gt;
      }
  
  }
  </code></pre>
  
  <p>And my <code>EventHandler</code> interface:</p>
  
  <pre><code>@FunctionalInterface
  interface EventHandler&lt;T&gt; {
  
      fun handle(event: T)
  
  }
  </code></pre>