safeCast

fun <T> safeCast(block: () -> T?): T?

Cast any object within without throwing any exception, except CancellationException to cancel parent jobs.

Return

the wanted type or null if exception was thrown.


inline fun <T> Any?.safeCast(): T?

Cast any object to the wanted type without throwing any exception, except CancellationException to cancel parent jobs.

Return

the wanted type or null if casting threw an exception.