h

    Hauke Radtki

    1 year ago
    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.
    ilya.gorbunov

    ilya.gorbunov

    1 year ago
    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:
    import kotlin.io.readBytes as kotlinReadBytes
    
    fun File.readBytes(...) = this.kotlinReadBytes(...)
    h

    Hauke Radtki

    1 year ago
    That does the trick, thank you very much!