How to create an anonymous implementation of an interface?

There are examples in the documentation for anonymous classes, but not for interfaces.

This is how I created an instance of an interface:

fun TileSet.union(another: TileSet) : TileSet =
    object : TileSet {
        override fun contains(x: Int, y: Int) : Boolean =
            this@union.contains(x, y) || another.contains(x, y)
    }

Notice that, unlike in the example from documentation, there are no parentheses after object : TileSet.

Leave a Comment