c99374747d884571d488d224b1fa0f6b by 2024
Author:2024
Language: eng
Format: epub
Published: 2024-06-29T17:08:29+00:00
Chapter 11
Anonymous, Lambdas, Object & Inline Functions
Languages that don't allow functions to exist as entities in their own right make things difficult without many advantages. Kotlin introduces features to allow functions to be treated in more flexible ways, in particular to be used as parameters to other functions. In this chapter we look at anonymous functions, object functions, function references, lambda functions and inline functions.
Many of Kotlin's language innovations are about how you can use functions.
As well as being able to use standalone "classical" functions, Kotlin also provides function expression and references, which allow you to pass functions to other functions. One of the problems is that this has resulted in a confusing menagerie of new and different function types.
When it comes to functions in Kotlin, there is usually more than one way to get a particular job done.
Anonymous Functions & References
What isn't as well known as it should be, is that you can create a variable of a function type and you can store a reference to a function in it, for example: typealias arith = (Int,Int)->Int
var myfunc:arith
myfunc = fun(a:Int,b:Int):Int{return a+b}
println(myfunc(1,2))
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
We Ride Upon Sticks by Quan Barry(33567)
The Secret History by Donna Tartt(17296)
Norse Mythology by Gaiman Neil(12244)
Crooked Kingdom: Book 2 (Six of Crows) by Bardugo Leigh(11574)
The Betrayed by Igor Ljubuncic(11395)
The Betrayed by Matthew Dickerson(11200)
Caraval Series, Book 1 by Stephanie Garber(9386)
Year One by Nora Roberts(8829)
Oathbringer by Brandon Sanderson(8771)
The City of Brass by S. A. Chakraborty(8083)
The Priory of the Orange Tree by Samantha Shannon(7816)
Red Rising by Pierce Brown(7691)
Twilight Siege: A Dark Fantasy Novel (The Fae Games Book 2) by Jill Ramsower(7469)
Confessions of an Ugly Stepsister by Gregory Maguire(7403)
Little Fires Everywhere by Celeste Ng(6440)
Shalador's Lady by Anne Bishop(6362)
Storm and Silence by Robert Thier(6153)
Shadows Of The Apt [01] - Empire in Black and Gold by Adrian Tchaikovsky(6122)
This Is How You Lose Her by Junot Diaz(6070)