kotlin extension method access in another kt

Viewed 4669

I'm thinking about adding a global extension method to String in just one file,and wherever i use a String i can always use this extension.

But i failed to find a way to do so...i just paste the extension everywhere now.

extension here in A.kt:

class A{
    ......
    fun String.add1(): String {
        return this + "1"
    }
    ......
}

and access like this in B.kt:

class B{
    fun main(){
        ......
        var a = ""
        a.add1()
        ......
    }
}

I've tried everyting i can add like static and final but nothing worked.

2 Answers
Related