ansman
09/16/2019, 2:39 AM// Common
expect class Input
interface Foo {
fun doStuff(input: Input)
}
// JVM
actual typealias Input = InputStream
// Use site
object : Foo {
// I want this type to be `InputStream` when implementing this
override fun doStuff(input: Input) {
...
}
}
Nicholas Bilyk
09/16/2019, 2:15 PMansman
09/16/2019, 2:17 PMinput
is already a InputStream
. You can actually just change the argument type to be InputStream
. Most of my `expect`s are internal
to not pollute the global namespace but then the default implementation is red since Input
is not accessibleNicholas Bilyk
09/16/2019, 2:19 PMansman
09/16/2019, 2:19 PMexpect
types to the consumer if it’s a typealias
Nicholas Bilyk
09/16/2019, 2:26 PMansman
09/16/2019, 2:28 PMInput = InputStream.
I don’t want consumers of the library to have to feel like it’s a separate type when it’s actually just an InputStream
. Ideally the fact that it’s called Input
in the common code should be an implementation detail and should not concern the consumersNicholas Bilyk
09/16/2019, 2:31 PMansman
09/16/2019, 2:32 PMNicholas Bilyk
09/16/2019, 2:33 PMansman
09/16/2019, 2:34 PMInput
didn’t exist for them. I hoped making it internal
would do just that and I suppose it did to some extent. But instead you get compile errors unless you manually change Input
to InputStream
Nicholas Bilyk
09/16/2019, 2:35 PMinterface NativeReadBuffer<T> : ReadBuffer<T> {
/**
* Returns the underlying native implementation of this Buffer. For JVM it will be an nio.Buffer object, for
* js it will be an ArrayBuffer
*/
val native: Any
}
ansman
09/16/2019, 2:45 PM@JvmName
or something like that. I don’t need to specify the full path name but rather just a typealias