I am totally new to Kotlin and researching the right book to use for teaching myself.
I love other Head First publications on programming topics due to the format.
I was reading online about special features that Kotlin has that Java does not.
I cam across Extension Functions.
The examples given on the https://kotlinlang.org/docs/reference/extensions.html site are functions like sort.
Paraphrasing: The argument is that this extension function allows you to extend the class without having to inherit from the class.
I was wondering if you could elaborate on the benefits of using this new functionality in Kotlin and why this feature is beneficial?
How would you use this functionality in a real world situation?
Extension functions give you the ability to teach existing classes new tricks. :-) When you create an extension function, it feels like you are teaching some existing class a new method. In reality, the compiler will track down any calls to the new extension function and replace it with a call to the extension. This means that although it *looks* like you are adding new methods to existing classes, you not. It's a trick that's played at compile time, and so calls to extensions are always statically resolved (i.e. the code they call is always resolved at compile time, rather than run time).
That was a great question. Hope you enjoy the book
Head First Android Development
posted 2 months ago
Thank you for your response.
The way you explain that made it much easier to understand than the explanation on the Kotlin site.
I will add that to my tool bag for later and see what other questions may be of use to others reading up on Kotlin.
Thank you again!
These are not the droids you are looking for. Perhaps I can interest you in a tiny ad?
Create Edit Print & Convert PDF Using Free API with Java