← thecodex.expert · The Codex Family of Knowledge

Kotlin Playground

Real Kotlin, compiled and run for real — powered by the official JetBrains Kotlin Playground widget below. Unlike the other in-browser playgrounds on this site, your code is sent to JetBrains' own compile servers and the real output comes back — the same backend that runs kotlinlang.org's own examples.

● Live (JetBrains servers) Kotlin 2.3 Official widget
fun main() { // Welcome to the Kotlin playground! // Click the green Run button below to execute. data class User(val name: String, val role: String) val team = listOf( User("Ada Lovelace", "admin"), User("Grace Hopper", "member") ) val admins = team.filter { it.role == "admin" } println("Team size: ${team.size}") println("Admins: ${admins.map { it.name }}") // Null safety val maybeName: String? = team.firstOrNull { it.role == "owner" }?.name println("Owner: ${maybeName ?: "none"}") }

Editable in place  ·  Real compilation on JetBrains' servers  ·  Same backend as the official Kotlin docs

Try these examples

Each card below is its own live, runnable Kotlin snippet — click Run on any of them.

Data classes & destructuring
data class Point(val x: Int, val y: Int) { operator fun plus(other: Point) = Point(x + other.x, y + other.y) } fun main() { val a = Point(1, 2) val b = Point(3, 4) val (x, y) = a + b println("Sum: ($x, $y)") println("Auto toString(): ${a + b}") }
Sealed classes & when
sealed class Shape { class Circle(val radius: Double) : Shape() class Rectangle(val width: Double, val height: Double) : Shape() } fun area(shape: Shape): Double = when (shape) { is Shape.Circle -> Math.PI * shape.radius * shape.radius is Shape.Rectangle -> shape.width * shape.height // No 'else' needed — the compiler knows these are the only cases } fun main() { val shapes = listOf(Shape.Circle(3.0), Shape.Rectangle(4.0, 5.0)) shapes.forEach { println("Area: %.2f".format(area(it))) } }
Coroutines
import kotlinx.coroutines.* suspend fun fetchUser(id: Int): String { delay(100) // simulate network latency return "User#$id" } fun main() = runBlocking { val a = async { fetchUser(1) } val b = async { fetchUser(2) } println("Loaded: ${a.await()} and ${b.await()}") }
Extension functions
fun String.isPalindrome(): Boolean { val cleaned = this.lowercase().filter { it.isLetterOrDigit() } return cleaned == cleaned.reversed() } fun main() { val words = listOf("racecar", "kotlin", "A man a plan a canal Panama") words.forEach { println("\"$it\" -> ${it.isPalindrome()}") } }

How this works

Unlike the SQL, Python, JavaScript, and TypeScript playgrounds on this site — which run entirely inside your browser via WebAssembly or a JavaScript sandbox — Kotlin has no practical way to compile and run client-side. Kotlin's compiler targets the JVM (and JS/Native backends), and there's no browser-based Kotlin compiler comparable to Pyodide for Python.

So this page embeds the official Kotlin Playground widget, maintained by JetBrains (the creators of Kotlin). When you press Run, your code is sent to JetBrains' own compile servers, compiled for real, executed, and the actual output streams back — the same infrastructure that powers the runnable examples on kotlinlang.org itself. It's genuinely live execution; it just happens on JetBrains' servers rather than in your browser tab.

What to try next