Animesh Sahu
04/28/2020, 2:09 PMfun <T : Any> store(key: String, value: T, serializer: KSerializer<T>) {
json.stringify(serializer, value)
}
//To, maybe reified
fun <T : SomeSuperTypeForSerializable> store(key: String, value: T) {
json.stringify(T.serializer(), value)
}
Animesh Sahu
04/28/2020, 2:39 PMAnimesh Sahu
04/28/2020, 2:40 PMinline fun <reified T: Any> store(key: String, value: T) {
val serializer = T::class.serializer()
}
Nikky
04/28/2020, 3:04 PMAnimesh Sahu
04/28/2020, 3:05 PMAnimesh Sahu
04/28/2020, 3:05 PMbartvh
05/04/2020, 11:05 AMT
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.Nikky
05/04/2020, 9:56 PM@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