DEV Community

Discussion on: Share a code snippet in any programming language and describe what's going on

Collapse
 
jmfayard profile image
Jean-Michel πŸ•΅πŸ»β€β™‚οΈ Fayard • Edited
fun String.likeACow() = "Moo $this mooo"
Enter fullscreen mode Exit fullscreen mode

Same thing in Kotlin, super handy.

EDIT: A big advantage with for example the JavaScript version monkey-patching String.prototype, is that the String class is not modified everywhere in your codebase.

It works like a normal function, you import the new function only if and where you need it. See kotlinlang.org/docs/extensions.htm...