I have an object with a function which uses generi...
# getting-started
m
I have an object with a function which uses generics:
Copy code
import com.mongodb.client.MongoCollection
import org.litote.kmongo.KMongo
import org.litote.kmongo.getCollection
import kotlin.reflect.KClass

object PersistenceManager {

    fun <T : Any> createCollection(clazz: KClass<T>): MongoCollection<T> {
        val client = KMongo.createClient()
        val database = client.getDatabase("test")
        val collection = database.getCollection<clazz>()
        return collection
    }

}
The parameter
clazz
is shown as unused and the compiler complains
Unresolved reference: clazz
in the line
val collection = database.getCollection<clazz>()
. I don’t understand why. Can someone explain it to me and point me into the direction of a correct implementation, please?