- 
                Notifications
    You must be signed in to change notification settings 
- Fork 1.1k
Description
Today I was surprised, that I can't express the same update with Kotlin, which I can express with Java's MongoOperations API. My code was
mongoTemplate.updateMulti(
    Query.query(Criteria.where("someField").type(JsonSchemaObject.Type.DOUBLE)),
    AggregationUpdate.update()
        .set(...),
  MyEnt::class.java
)Usually Kotlin extension allows me to write the same code, but without ugly ::class.java. So I would expect the following to work:
mongoTemplate.updateMulti<MyEnt>(
    Query.query(Criteria.where("someField").type(JsonSchemaObject.Type.DOUBLE)),
    AggregationUpdate.update()
        .set(...)
)but it does not compile.
The reason is that the signature of Kotlin extension for MongoOperations is different from the one defined on the original MongoOperations interface method:
Lines 538 to 540 in 3342c75
| inline fun <reified T : Any> MongoOperations.updateMulti(query: Query, update: Update, collectionName: String? = null): UpdateResult = | |
| if (collectionName != null) updateMulti(query, update, T::class.java, collectionName) | |
| else updateMulti(query, update, T::class.java) | 
Line 1511 in 3342c75
| UpdateResult updateMulti(Query query, UpdateDefinition update, Class<?> entityClass); | 
The Kotlin extension accepts a more narrow type org.springframework.data.mongodb.core.query.Update type, while the Java interface accepts a more generic org.springframework.data.mongodb.core.query.UpdateDefinition.
By looking at the implementation of the Kotlin extension, I see not reasons for it to accept a different type. So, I think the type accepted by Kotlin extension function should be aligned with the one defined on the original interface it extends.