How do I use an extension function that's nested i...
# announcements
s
How do I use an extension function that's nested in an object from outside that object? i.e.
Copy code
object Example {
    fun String.exampleExtension() {
    }
}

fun test(str: String) {
    str.exampleExtension() // Doesn't work. How can I use the extension function?
}
s
simplest way:
Copy code
with(Example) {
  str.exampleExtension()
}
but passing
Example
to any function that takes
T.() -> *
will work, like
apply
also might be able to do a “static” import™
don’t quote me on that one though
s
works perfectly. Thanks!
👍 1