July 2018
Intermediate to advanced
336 pages
9h 23m
English
As in any programming language, Kotlin does support functions to be written and it enables users to write very concise functions such as the following, without any curly braces, start, and end keywords:
// This is an inline function which adds two Int valuesfun add(n1: Int, n2: Int): Int = n1 + n2;
More descriptive functions with well-defined content are as follows:
/*This is a descriptive function which adds two Double values */fun add(n1: Double, n2: Double): Double { return n1 + n2;}
A function that doesn't return anything (effectively a procedure) can be written as follows:
fun addAndPrint(n1: Int, n2: Int): Unit { println("$n1 + $n2 = ${n1 + n2}");}fun substractAndPrint(n1: Int, n2: Int) { println("$n1 - $n2 = ${ ...
Read now
Unlock full access