Scoped Extensions and Companion Extensions
Limit extension visibility and add extensions to companion objects.
Why Scope Extensions?
By default, extensions are visible wherever imported. Scoping limits visibility to a class, file, or context — reducing namespace pollution and improving discoverability.
File-Private Extensions
Mark an extension function private at file level to scope it to that file only.
private fun String.shout() = uppercase() + "!"
fun main() {
println("hello".shout()) // HELLO!
}All lessons in this course
- Extension Functions: Syntax and Dispatch Rules
- Extension Properties and Computed Extensions
- Scoped Extensions and Companion Extensions
- Practical Extensions: Context, View & String Helpers