Running These Snippets in an IDE
You are also welcome to try these Kotlin snippets outside of the Klassbook.
Android Studio and IntelliJ IDEA each has a Kotlin REPL, available from the Tools > Kotlin > Kotlin REPL main menu option:
The Klassbook is set up to run your main()
function when you click the “Run” button. Android Studio’s and IDEA’s REPL is not. If you copy a Klassbook snippet and paste it into the REPL, you will need to call main()
yourself, by simply typing main()
onto a separate line after the pasted-in code. Then, click the green “run” triangle button, or press Ctrl-Enter on Windows/Linux machines, to run the code. The output will be printed in green italics immediately below your code:
A few code snippets will not work in the Android Studio/IDEA REPL. That is because Klassbook is using Kotlin/JS, whereas Android Studio and IDEA use Kotlin/JVM. Most of the Kotlin that we see will be the same between those platforms, but there will be occasional differences.
Also, any code snippets that print more than one line will not work well in the IDE-based REPLs. They will tend to combine all the output onto one line:
Prev Table of Contents Next
This book is licensed under the Creative Commons Attribution-ShareAlike 4.0 International license.