If I did not remember what component2 was, I could use the built-in :t command. No cookies – I love it already! But what is this mysterious component2 I used? Let’s find out. To illustrate this, let’s try to determine which HTTP headers the site sets when we’re visiting it. It allows me to add a library from Maven Central to my classpath. Ki has the :dependsOn construct for this particular scenario. For example, I like to use the Fuel HTTP client for HTTP interaction because it has an intuitive API. I may need to use a library, or write a throw-away one-liner using a 3rd-party library. However, sometimes my experiments are a bit more complex than testing a random snippet. Each command is stored independently, which ensures I’ll be able to find any previous commands and reuse them. The nice thing we’ve kept from the original REPL in kotlinc is: every intermediate result is being written into variables named res0, res1, and so on. One more thing to notice is that ki highlights the code, so it will be easier for me to read the code I wrote several inputs ago. This is a thing of the past with ki, as there is autocompletion to help! Here’s a quick example of how easy it is to write code in ki with the help of autocompletion. Before ki, you had to go through the documentation a lot while working with kotlinc. The Kotlin collection API is huge, and it’s not humanly possible to remember everything it contains. I like doing quick experiments with collections to find out what they have, what they do, and how I can obtain the desired result. Special paste mode to paste large snippets found somewhere.Kotlin REPL is very powerful, but it forces you to open IntelliJ IDEA, which is not always convenient.Īllow me to introduce you to ki, a Kotlin Interactive Shell, and describe its benefits below. kotlinc does not have autocomplete or syntax highlighting. There are several options to run Kotlin interactively: kotlinc and Kotlin REPL ( read-evaluate-print loop) in IntelliJ IDEA.
0 Comments
Leave a Reply. |