nikolaymetchev
09/23/2022, 10:48 AMclass A {
fun String.hello() {}
}
fun String.hello2() {
A().hello() // cannot find hello()
}
nikolaymetchev
09/23/2022, 10:49 AMclass A {
fun String.hello() {}
}
fun String.hello2() {
with(A()) {
hello()
}
}
nikolaymetchev
09/23/2022, 10:49 AMwith
call it doesn’t compile again.wbertan
09/23/2022, 10:53 AMfun String.hello() {}
it is an extension to be called on a String
A().hello()
, A
isn't a String
, so you can't call hello
.
fun String.hello2() {
you can call the hello
there, because it will be called on the String
of hello2
.wbertan
09/23/2022, 10:54 AMclass A {
fun hello(valueHello: String) {}
}
fun hello2(valueHello2: String) {
with(A()) {
hello(valueHello2)
}
}
Matteo Mirk
09/23/2022, 10:57 AMnikolaymetchev
09/23/2022, 11:00 AMKlitos Kyriacou
09/23/2022, 1:35 PM