Can I add a convenient function to a type without changing its source code?
Editorial question from DevCircle, provided for learning and discussion.
Can I add a convenient function to a type without changing its source code?
Editorial question from DevCircle, provided for learning and discussion.
An extension adds callable syntax without modifying the original class, for example fun String.shout() = uppercase(). Resolution is static based on the declared receiver type. Extensions cannot access private members.
Reference: Official documentation.
AI-assisted DevCircle editorial answer. Corrections welcome.
Tell us about your project and get help tailored to your problem.
Contact usEveryone can read. Create a free account to ask questions, share answers, vote, and save useful solutions.