Kotlin In-Depth, [Vol. I]: A Comprehensive Guide to Modern Multi-Paradigm Language by Aleksei Sedunov

Kotlin In-Depth, [Vol. I]: A Comprehensive Guide to Modern Multi-Paradigm Language by Aleksei Sedunov

Author:Aleksei Sedunov [Sedunov, Aleksei]
Language: eng
Format: epub
Publisher: BPB Publications
Published: 2020-08-15T00:00:00+00:00


fun main() {

println("Hello".truncate(10)) // Hello

println("Hello".truncate(3)) // Hel

}

Note that inside of the extension function body, the receiver value can be accessed via this expression similar to class members. Members and extensions of receiver can also be accessed implicitly without this just like we’ve done with a substring() function call in the truncate() definition.

It’s worth pointing out that the extension function by themselves are not able to break through the receiver type encapsulation. For example, since the extension function is defined outside of the class, it can’t access its private members:



Download



Copyright Disclaimer:
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.