Search code examples
functionkotlinextension-methodsaccess-modifiersextension-function

What is the effect of access modifiers on extension functions?


What will happen if I change the access modifier of an extension function to private? Does it have any effect? Does it matter?!

private fun String.myExtensionFunction() { // ... }


Solution

  • The extension method will only be seen in the class/file it is declared in.

    Without private the extension method would be public and could be called from the outside.