Hi. A question about function references. Say I have two packages,
foo
and
bar
.
in
bar.Baz.kt
I have this:
Copy code
package bar
fun baz(i: Int) = i + 1
and in
foo.Foo.kt
this:
Copy code
package foo
import bar.baz
fun xd(op: (Int) -> Int) {
println("calling $op with param 4 and getting ${op(4)}")
}
fun main() {
xd(::baz)
}
everything works great.
now I want to get rid of
import bar.baz
. How do I do that?
xd(::bar.baz)
does not compile. What’s the syntax here?
r
rkechols
12/10/2022, 8:23 AM
If I'm not mistaken (which is an easy thing to happen)...
It's impossible to use a function (or anything) from another package without it being imported.
If I'm incorrect, somebody please correct me, but that's my understanding.
j
Joffrey
12/10/2022, 8:25 AM
It's actually incorrect. You can use fully qualified names for almost everything actually
j
Jakub Gwóźdź
12/10/2022, 8:26 AM
so what would be the syntax for it, @Joffrey? without using