kotlin.checkNotNull

checkNotNull

inline fun <T : Any> checkNotNull(value: T?): T

Throws an IllegalStateException if the value is null. Otherwise returns the not null value.

import kotlin.test.*

fun main(args: Array<String>) {
//sampleStart
var someState: String? = null
fun getStateValue(): String {
    val state = checkNotNull(someState) { "State must be set beforehand" }
    check(state.isNotEmpty())