So I'm trying to create a generic SQLDelight Colum...
# android
h
So I'm trying to create a generic SQLDelight ColumnAdapter class with a subtype of
SettingsCollection
as a parameter, but from what I understand, KotlinX.Serialization requires a reified type parameter, which isn't available at the class level. I don't really understand generics and reification if I'm honest. Does anyone have any pointers? Is this even possible?
Copy code
class SettingsColumnAdapter<T: SettingsCollection>(val collectionType: T) : ColumnAdapter<T, String> {
    override fun decode(databaseValue: String): T {
        return Json.decodeFromString(databaseValue)
    }

    override fun encode(value: T): String {
        return Json.encodeToString(value)
    }
}
d
Are you trying to use reflection or some compile time generated implementation?
Reflection isn't available on T type, even in pure Java.
reified parameter is a T generic parameter which will be translated as a KClass of T type. It isn't available in classes, but only in inlined functions. As these will be copied into source code.
you should do something like: class IWantSomeReflectionOfT<T : Any>(clazz: KClass<T>) {} inline fun <retified T> buildAboveClass() = IWantSomeReflectionOfT(T::class)