com.kamelia.sprinkler.util.Typing.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of utils Show documentation
Show all versions of utils Show documentation
Sprinkler@utils | Black Kamelia
package com.kamelia.sprinkler.util
/**
* Casts this nullable object to the specified type [T].
*
* @receiver the object to cast or null
* @return the object cast as [T]
*/
@Suppress("UNCHECKED_CAST", "NOTHING_TO_INLINE")
inline fun Any?.unsafeCast(): T = this as T
/**
* Tries to cast this nullable object to the specified type [T].
* If the cast fails, returns null.
*
* @receiver the object to cast or null
* @return the object cast as [T] or null if the cast fails
*/
inline fun Any?.castOrNull(): T? = this as? T