I’ve got the following problem: here’s an interface called `Source`:
Copy code
interface Source : Closeable {
@Throws(IOException::class)
fun read(sink: Buffer, byteCount: Long): Long
}
I’m declaring
SuspendingSource
like this:
Copy code
interface SuspendingSource : Source {
@Throws(IOException::class)
override suspend fun read(sink: Buffer, byteCount: Long): Long
}
which doesn’t compile because of
Conflicting overloads
. Is it forbidden to override non-suspend functions with suspend ones?
d
Dominaezzz
10/14/2018, 6:43 PM
Yes, it is forbidden. Since the anyone calling
Source.read
doesn't not know to suspend.
e
egorand
10/14/2018, 6:47 PM
Ah, makes sense
b
Burkhard
10/14/2018, 11:42 PM
It’s also quite intuitive if you look at the generated bytecode of a suspend function. They work by passing a hidden extra argument which tells the function where to resume.