0

I wanted to use kotlin.time.measureTime in a Kotlin scratch file but it doesn't work.

...
kotlinOptions {
    ...
    freeCompilerArgs = ["-Xopt-in=kotlin.time.ExperimentalTime"]
}

experimental-annotation

Of course in my scratch file I "use classpath of module" which defines the compiler argument. When I use measureTime in regular code it works fine, but in the scratch file doesn't.

Michał Klimczak
  • 12,674
  • 8
  • 66
  • 99

2 Answers2

1

@OptIn works for me (see alternative recommendation by IntelliJ IDEA).

@OptIn(ExperimentalTime::class)
val s = measureTime { sleep(10) }
println(s)
0

Try to use explicit declaration of experimental API usage inside scratch file:

@ExperimentalTime
val s = measureTime {
    
}
  • Unfortunately it doesn't help. The annotation is "applicable" but the code still fails in runtime with the same error - This declaration is experimental and its usage must be marked with '@kotlin.time.ExperimentalTime' or '@OptIn(kotlin.time.ExperimentalTime::class)' – Michał Klimczak Nov 19 '20 at 09:43