Citizen function

With Kotlin, there's a more efficient way to implement the same functionality using fewer classes. That's thanks to the fact that functions in Kotlin are first-class citizens.

What does that mean? 

For one, we can assign functions to the variables of our class, like any other normal value. 

It makes sense that you can assign a primitive value to your variable:

val x = 7

You could either assign an object to it:

var myPet = Canary("Michael")

So, why should you be able to assign a function to your variable? As follows:

val square = fun (x: Int): Long {
return (x * x).toLong()
}

With Kotlin, this is totally valid. 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.189.180.43