Found out myself, used reflections here, althrough use is discouraged, it looks cleaner, because they are inferred
Animesh Sahu
04/28/2020, 2:40 PM
Copy code
inline fun <reified T: Any> store(key: String, value: T) {
val serializer = T::class.serializer()
}
n
Nikky
04/28/2020, 3:04 PM
but that only works on jvm, passing the serializer around would work on other platforms too (most likely)
a
Animesh Sahu
04/28/2020, 3:05 PM
JVM is most stable so, atleast work there😜
Animesh Sahu
04/28/2020, 3:05 PM
Better than nothing :V
b
bartvh
05/04/2020, 11:05 AM
Would be really nice, but I think it would get quite complicated in Kotlin as it is right now, because the compiler wouldn't just need to know that
T
implements some interface that declares
serializer()
, it would in fact need to assert that
T
has a companion object that implements such an interface.
This is one of those areas where C++ templates really shine.
n
Nikky
05/04/2020, 9:56 PM
well it could also just look for a annotation on the class
@Serializable(with=...)
assuming the compiler can modify the annotation when it injects all the serializable stuff
that would at least only be a single marker on the type to match