Using an interactive shell (REPL)

Kotlin:
Using an interactive shell (REPL)

How to:

Launching Kotlin’s REPL is a breeze. Open your terminal and type kotlinc. You’ll land in the Kotlin shell. Let’s try defining a variable and printing its value:

Welcome to Kotlin version 1.7.10 (JRE 1.8.0_292-b10)
Type :help for help, :quit for quit
>>> val greeting = "Hello, Kotlin REPL!"
>>> println(greeting)
Hello, Kotlin REPL!

Deep Dive

Kotlin’s REPL debuted with the language to encourage experimentation. It’s similar to Python’s interactive shell but tailored for Kotlin’s syntax and peculiarities. Alternatives? Interactive environments in IDEs, such as IntelliJ IDEA, and online Kotlin playgrounds. The REPL works by compiling code on-the-fly, providing instant feedback – crucial for learning and debugging.

See Also