antoniomarin
09/24/2021, 10:59 AMdata class Test<T>(
val key: String,
val additionalData: T
)
inline fun <reified T> Test<*>.checkSafeCast(): Test<T>? {
return if (this.additionalData is T) {
this as Test<T> // Unchecked cast
} else {
null
}
}
Joffrey
09/24/2021, 12:39 PMinline fun <reified T> Test<*>.checkSafeCast(): Test<T>? {
return if (this.additionalData is T) {
@Suppress("UNCHECKED_CAST") // the above check guarantees the safety
this as Test<T>
} else {
null
}
}
antoniomarin
09/24/2021, 12:45 PMJoffrey
09/24/2021, 12:47 PM