The post briefs on REPL feature in IntelliJ IDEA and how to use it.
Using REPL feature in IntelliJ IDEA you can try out a piece of code on the fly outside the main code. REPL – stands for Read-Eval-Print Loop.
To open this option in the IDE choose,
Tools – > Kotlin – > Kotlin REPL – it opens a new window at the bottom of the screen.
Now to use REPL, type the code you want to try out in the section showing the hint <CTRL+ENTER> to execute
And then click on the green Run button to execute, after a pause you should be able to see the output.
While executing if your piece of code has error it will be shown in the REPL window
For example:
Print statement is written as println(“Hello World”) we wrote it as printl(“Hello World”), hence there is an error shown in the REPL window.
Now that you know how to use REPL feature on IntelliJ IDEA you can try out the code outside main code to be sure and then go for adding it in your main code.
For more post’s on Kotlin check out our Kotlin-Hacks section.
You can also checkout the YouTube video on the same