Level Up Your Extension Game
summary
Shows concrete rules and pitfalls for Kotlin extension functions with examples that compile and interop with Java, including using Android KTX to replace 70+ lines of Spannable setup with simple span extensions, how to declare a receiver (domesticAnimal.toAnimal), and how to call extensions from Java via the generated class mappersKt while noting inline only extensions are invisible to Java. Warns against extending common types like String for business logic, mutating receiver members, over-extending Context vs Activity, and recommends nullable receiver checks, type-to-type conversions, and iterator extensions for view groups.
AI-written summary · about
chapters (7)
- 0:00Introduction
- 1:15Why extension functions
- 3:01Creating extension functions
- 4:50Bad practices explained
- 7:40Context extension pitfalls
- 9:47Good practices overview
- 12:18Core KTX benefits
related talks
52mPowered by Kotlin
21mGetting the most out of Android KTX
40mAndroid Jetpack: Sweetening Kotlin development with Android KTX
31mSpring extensions for Kotlin
01h 03mKotlin on Android
01h 13mThe Magic of Kotlin Compiler Extensions
43mfun() Talk: Exploring Kotlin Functions
39mHow to Kotlin - from the lead Kotlin language designer
