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:
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.