doc / ch.tutteli.atrium.domain.builders.utils / nullable

nullable

inline fun <T> nullable(t: T): T?

Turns the given type into a nullable type.

Intended to be used in conjunction with platform types such as String! or in other words, when you deal with Java and you want to turn a platform type into a nullable type.

Basically it is a replacement for cast but without introducing one explicitly (we only give an additional hint to the compiler that we expect a nullable type and not a non-nullable one). For instance, instead of writing getPersons() as List<String>? you can write nullable(getPersons())

inline fun <T> nullable(t: KFunction0<T>): KFunction0<T?>
@JvmName("nullable1") inline fun <T1, R> nullable(t: KFunction1<T1, R>): KFunction1<T1, R?>
@JvmName("nullable2") inline fun <T1, T2, R> nullable(t: KFunction2<T1, T2, R>): KFunction2<T1, T2, R?>
@JvmName("nullable3") inline fun <T1, T2, T3, R> nullable(t: KFunction3<T1, T2, T3, R>): KFunction3<T1, T2, T3, R?>
@JvmName("nullable4") inline fun <T1, T2, T3, T4, R> nullable(t: KFunction4<T1, T2, T3, T4, R>): KFunction4<T1, T2, T3, T4, R?>
@JvmName("nullable5") inline fun <T1, T2, T3, T4, T5, R> nullable(t: KFunction5<T1, T2, T3, T4, T5, R>): KFunction5<T1, T2, T3, T4, T5, R?>

Turns the given function reference into a function reference with a nullable return type.

Intended to be used in conjunction with platform types such as String! or in other words, when you deal with Java and you want to turn the return type (which is a platform type) of your function into a nullable type.