// Created on savesnippets.com · https://savesnippets.com/qZKDSEo5CxYv3B object Database { private val cache = mutableMapOf() fun put(k: String, v: String) { cache[k] = v } fun get(k: String): String? = cache[k] fun size() = cache.size } fun main() { Database.put("api_url", "https://api.example.com") println(Database.get("api_url")) // https://api.example.com println(Database.size()) // 1 // Anonymous object — one-shot instance with interface override val handler = object : Runnable { override fun run() { println("running…") } } handler.run() // Anonymous object that captures from the enclosing scope var counter = 0 val ticker = object { fun tick() { counter++; println("tick $counter") } } ticker.tick(); ticker.tick() }