https://kotlinlang.org logo
Title
e

egorand

10/14/2018, 6:22 PM
I’ve got the following problem: here’s an interface called `Source`:
interface Source : Closeable {
  @Throws(IOException::class)
  fun read(sink: Buffer, byteCount: Long): Long
}
I’m declaring
SuspendingSource
like this:
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.