https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
h

Hauke Radtki

11/13/2020, 12:42 PM
Is there a way to reference an extension function by package? My issue: I want to
expect
an extension function that is available on some targets and not on others. E.g.:
File.readBytes():ByteArray
is defined in jvm but not on native. So I want to have an actual expression that references the existing extension function (located in
<http://kotlin.io|kotlin.io>
) for jvm and roll my own implementation for native targets.
i

ilya.gorbunov

11/13/2020, 4:28 PM
So you're trying to write actual
File.readBytes()
extension and can't call
readBytes
from
<http://kotlin.io|kotlin.io>
, because it is now shadowed by your extensions? In this case you can import
readBytes
with alias, and call it by the new alias then:
Copy code
import kotlin.io.readBytes as kotlinReadBytes

fun File.readBytes(...) = this.kotlinReadBytes(...)
🙏 1
h

Hauke Radtki

11/13/2020, 6:11 PM
That does the trick, thank you very much!
2 Views