Line 2 demonstrates the for-loop, that would have been called "enhanced" if there were any other for-loop in Kotlin
An "object-oriented" Hello
Here we have a class with a primary constructor and a member function.
Note that there's no new keyword used to create an object.
A multi-language Hello
else->"Sorry, I can't greet you in $language yet"
In this example, val denotes a declaration of a read-only local variable, that is assigned an if-expression. Then we use very basic pattern matching expression.
Extension function hello()
"world".hello()// prints 'Hello, world!'
In this snippet, we define an extension functionhello() for the type String that uses this in a string template. And then we call this function on a string "world", i.e. we pass this string as the receiver-argument (this-argument) to hello().
Here we first called the filter()higher-order function to select only those string from the args array that have non-zero length. To do this, we passed a function literal that checks the length of its parameter. the name it is the default name of a parameter for a function literal.
Filter created a collection for us, and we called foreach() on that collection, passing in a function literal to be executed for each element. And that function literal just prints a greeting with the passed string.