Hi, Its known that `kotlin.Result` can't be used ...
# announcements
a
Hi, Its known that
kotlin.Result
can't be used as return type for functions, unless used with the compiler flag
-Xallow-result-return-type
. So
fun parseInt(s: String) = runCatching { s.toInt() }
will not compile. But what I find weird is that it can be used in function literals, as follow:
val parseInt:(String)->Result<Int> = {n-> runCatching{n.toInt()}}
or:
val parseInt: (String)->Result<Int> = fun(n) = runCatching{n.toInt()}
The last two will compile correctly without using the compiler flag! Why and what's the difference? doesn't the same problem (i.e: future breaking changes) apply for both? or I'm missing something?