Overview - Extensions vs member functions priority
What is it?
In Kotlin, both member functions and extension functions can be called on an object. Member functions are defined inside a class, while extension functions are defined outside the class to add new functionality without modifying the original class. When both a member function and an extension function have the same name and signature, Kotlin decides which one to call based on a priority rule. This topic explains how Kotlin chooses between them.
Why it matters
Understanding which function Kotlin calls when both member and extension functions exist prevents bugs and confusion. Without this knowledge, developers might expect an extension function to run but the member function runs instead, leading to unexpected behavior. This clarity helps write safer, more predictable code and use extensions effectively.
Where it fits
Before learning this, you should know basic Kotlin syntax, classes, and functions, including how to define member and extension functions. After this, you can explore more advanced Kotlin features like higher-order functions, function overloading, and polymorphism.