Functions with no parameter and no return type

This is the simplest form of a function. See the following example:

 fun sayHello(){
println("Hello from Kotlin")
}

If a function does not return a value, the Unit keyword can be declared right after the function name.

Unit corresponds to the void type in Java.

The Unit keyword is optional. If no keyword is mentioned, Kotlin will consider Unit as a default value:

fun sayHello() : Unit{
println("Hello from Kotlin")
}
..................Content has been hidden....................

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