Kotlin 1.3 has a Result<T> type if you opt into inline classes

Looks like maybe you don’t have to opt into inline classes to use Result, even though Result itself is an inline class? What is the motivation behind why Result was not parametrized over the error type?

Because Result is guaranteed to be stable.

Can Result be used as a return type in a function? The following code snippet will yield an error:

fun foo(): Result { // error ‘kotlin.Result’ cannot be used as a return type
return Result.success(“foo”)
}

You should use String instead.

“guaranteed to be stable” <---- Can you explain?

https://kotlinlang.org/docs/reference/evolution/components-stability.html

Perfect, thanks.

1 Like