19

I encountered a problem with Kotlin Flow.

I copied the following code code from the Official guide

fun simple(): Flow<Int> = flow { 
    for (i in 1..3) {
        delay(100) 
        emit(i) 
    }
}

But the Android Studio prompts a following error:

No type arguments expected for class Flow

What am I doing wrong?

Phil Dukhov
  • 67,741
  • 15
  • 184
  • 220
巴赫哥德尔
  • 193
  • 1
  • 4

1 Answers1

91

Make sure you use import kotlinx.coroutines.flow.Flow not java.util.concurrent.Flow, it gives you this error because Java concurrent Flow class take 0 type arguments, but Coroutines Flow take one

AmrDeveloper
  • 3,826
  • 1
  • 21
  • 30