CLOVIS
09/10/2026, 3:56 PMinterface Ref<T> {
…
}
In some situations, the type T isn't the one you want, in a way that the compiler cannot verify. For example if you have very arbitrary data, you may want to just treat it as a Ref<JsonObject> .
How should I name the function that changes the type? The name should be clear that the correctness is not verified (it can cause future deserialization to fail, it's a type-safety bypass):
• unsafeCast
• reinterpret
• something else?mbonnin
09/10/2026, 3:57 PMCLOVIS
09/10/2026, 3:58 PMmbonnin
09/10/2026, 3:58 PMCLOVIS
09/10/2026, 3:59 PMval a: Ref<A> = …
val b: Ref<B> = a.xxx<B>()CLOVIS
09/10/2026, 4:00 PMa.downcast<B>() which gives B)mbonnin
09/10/2026, 4:04 PMkotlin-stdlib (not public):
inline fun <reified T : Any> Any?.safeAs(): T? = this as? T
inline fun <reified T : Any> Any?.cast(): T = this as T
inline fun <reified T : Any> Any?.assertedCast(message: () -> String): T = this as? T ?: throw AssertionError(message())
If the function is framework specific, I'd stay clear of "cast"bod
09/10/2026, 4:06 PMconvertYoussef Shoaib [MOD]
09/10/2026, 4:13 PMdeserializeAs?
Maybe it doesn't even have to be tied to deserialization at all, so something like map could do the trick, where inside you'd spell out the transformation logic (which can be as simple as using kotlinx-serialization to turn JSON into a data class).CLOVIS
09/10/2026, 4:13 PMCLOVIS
09/10/2026, 4:14 PMconvert is already a function of this class and it actually transforms the data 😅bod
09/10/2026, 4:14 PMtransform 😄Youssef Shoaib [MOD]
09/10/2026, 4:16 PMreinterpret thenCLOVIS
09/10/2026, 4:26 PMtransform conveys that the data is changed in some way, whereas this function really doesn't, it just changes the Kotlin type for itbod
09/10/2026, 4:28 PMfacet ? not sure what exactlybod
09/10/2026, 4:29 PM.fromACertainPointOfView() 😄mbonnin
09/10/2026, 4:33 PMthe<T>() gradle intensifiesYoussef Shoaib [MOD]
09/10/2026, 4:49 PMspillThe<T>() for the Gen Z appealphldavies
09/10/2026, 5:47 PM.transmute<T>() or .transmogrify<T>() have my vote.andylamax
09/14/2026, 10:43 AM.asRef<T>