There is a function. It is shown below.
fun <E, T : Collection<E>> constructCollectionType(collectionClass: Class<T>, elementClass: Class<E>): JavaType {
return mapper.typeFactory.constructCollectionType(collectionClass, elementClass)
}
I call the function above in other function. The code is shown below.
val type = constructCollectionType<Sku, MutableList<Sku>>(MutableList<Sku>::class, Sku::class.java)
Then, kotlin compile give me an error.
Only classes are allowed on the left hand side of a class literal.
The only way I found is Reified type parameters. The code is shown below.
inline fun <reified E, reified T: Collection<E>> constructCollectionType():JavaType {
return mapper.typeFactory.constructCollectionType(T::class.java, E::class.java)
}
Then, The call-site code is shown below.
jsonMapper.constructCollectionType<Sku, MutableList<Sku>>()
Is there any other solution ?