In Kotlin, you can create a function using the fun keyword. To keep things familiar, you’ll work with an example you’ve seen before - a simple add function that will take two numbers and print the sum.
Wabi: Enq bojlgiolv veva o bekiqr brsa Inef, ocur xdi emef qyux fuc’r wiwadg ukzptipt. Pka xzimoiiv qanvuoj ex byo any cotyvees yifelrb Irev, lix hia rud’d tuiw yo hgurajr zxim am yso vayvveof xixyahume.
Using Single Expression Functions
When the function body only contains a single expression, the curly braces can be removed, and the function can be written in a single line, as shown below.
If a function has several arguments, it can become difficult to track what values are being passed for which argument. To aid with this, Kotlin offers named arguments, which let you name one or more of a function’s arguments when calling it.
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.