https://kotlinlang.org logo
#codereview
Title
# codereview
h

Haris Khan

05/11/2021, 2:51 AM
There's this reified function that I'm calling... Is it possible to generically call it?
Copy code
inline fun <reified T : Any> MongoCollection<T>.replaceOne(
    replacement: T,
    options: ReplaceOptions = ReplaceOptions()
): UpdateResult = replaceOneById(KMongoUtil.extractId(replacement, T::class), replacement, options)
I want to create a wrapper around it like so :
Copy code
inline fun <reified T : Any> insertOrReplaceOne(document: T) {
        collection.replaceOneById
    }
Collection is of type MongoCollection<T> ... but the extension function fails to be applicable for some reason (this is a function in a parameterized class if it matters (same type T)) aka
Copy code
abstract class BaseMongoPlatformRepository<T : Any> { }
🚫 1
ah that sucks 😞 ... I was able to have my function accept a KClass and work around this limitation
5 Views