castOrElse

@JvmName(name = "castOrElse")
inline fun <T : Any> castOrElse(obj: Any?, kClass: KClass<T>, default: () -> T): T

Casts the given obj to T or returns the default if the cast fails.

Return

The cast object or default.

Parameters

obj

The object to cast.

kClass

The class to cast to.

default

The default value to get and return if the cast fails.

T

The type to return.