I am thinking of adding a global extension method to String in only one file, and wherever I use String, I can always use this extension.
But I could not find a way to do this ... I just paste the extension everywhere.
extension here in A.kt:
class A{
......
fun String.add1(): String {
return this + "1"
}
......
}
and access this in B.kt:
class B{
fun main(){
......
var a = ""
a.add1()
......
}
}
I tried everything I can add as staticand final, but nothing worked.
source
share