title: How to create an anonymous implementation of an interface?
body: <p>I have an interface:</p>
  
  <pre><code>interface TileSet {
      fun contains(x: Int, y: Int) : Boolean
  }
  </code></pre>
  
  <p>I want to be able to create unions of sets of tiles (tile is a pair of x and y integer coordinates):</p>
  
  <pre><code>fun TileSet.union(another: TileSet) : TileSet = 
     // ..
  </code></pre>
  
  <p>In Java 8, I could do it like this:</p>
  
  <pre class="lang-java prettyprint-override"><code>@FunctionalInterface
  public interface TileSet {
      boolean contains(int x, int y);
  
      public default TileSet unite(TileSet another) {
          return (x, y) -&gt; TileSet.this.contains(x, y) &amp;&amp; another.contains(x, y);
      }
  }
  </code></pre>
  
  <p>So an interface is implemented with a lambda in <code>TileSet#unite()</code>. Or it could be implemented with the old anonymous class approach:</p>
  
  <pre class="lang-java prettyprint-override"><code>public default TileSet unite(TileSet another) {
      return new TileSet() {
           @Override
           public boolean contains(int x, int y) {
               return TileSet.this.contains(x, y) &amp;&amp; another.contains(x, y);
           }
      }
  }
  </code></pre>
  
  <p>How can I create an anonymous implementation of a single-method interface in Kotlin?</p>
  
  <p>I know how to do it if I use <code>(Int, Int) -&gt; Boolean</code> instead of <code>TileSet</code>, but I want the type to have a descriptive name rather than just a function signature.</p>