{% include JB/setup %}
Kotlin is a cross-platform, statically typed, general-purpose programming language with type inference. It is designed to interoperate fully with Java, and the JVM version of its standard library depends on the Java Class Library, but type inference allows its syntax to be more concise.
%kotlin fun square(n: Int): Int = n * n
Kotlin context is accessible via kc
object bound to the interpreter. It holds vars
and functions
fields that return all user-defined variables and functions present in the interpreter. You can also print variables or functions by calling kc.showVars()
or kc.showFunctions()
.
fun square(n: Int): Int = n * n val greeter = { s: String -> println("Hello $s!") } val l = listOf("Drive", "to", "develop") kc.showVars() kc.showFunctions()
Output:
l: List<String> = [Drive, to, develop] greeter: (String) -> Unit = (kotlin.String) -> kotlin.Unit fun square(Int): Int