Alexander Finn
04/22/2020, 4:29 PMinline fun <reified TDocument : Any> getCollection(
collectionName: String = KMongoUtil.defaultCollectionName(TDocument::class)
): CoroutineCollection<TDocument>
In my code I want to create an interface with a default method that would return a collection for specified type:
interface MongoDBRepository<T: Any> {
val client: CoroutineClient
fun collection(): CoroutineCollection<T> {
return client.getDatabase(accountId).getCollection<T>()
}
}
However, the compiler complains that 'T' can not be used as a reified type parameter here. And defining a reified type parameter would require me to change collection() to an inline function which is something I can not do in an interface. Any thoughts on how to change the code to make an interface functional? Or am I doing something completely wrong?giylmi
04/22/2020, 5:47 PMDennis Schröder
04/23/2020, 7:41 AMgiylmi
04/23/2020, 7:42 AMimport io.ktor.client.HttpClient
import <http://io.ktor.client.request.post|io.ktor.client.request.post>
interface BaseApi {
val client: HttpClient
}
suspend inline fun <Request: Any, reified Response: Any> <http://BaseApi.post|BaseApi.post>(url: String, request: Request? = null): Response {
return <http://client.post|client.post>(url) {
request?.let {
body = it
}
}
}