How to invork method like this: <U> Subquery<U> subquery(Class<U> type);


class SubBasicSpec<Entity, SubEntity> : Specification<Entity> {
    override fun toPredicate(root: Root<Entity>?, query: CriteriaQuery<*>?, cb: CriteriaBuilder?): Predicate? {
        val subQuery = query?.subquery<Entity>( // not ok
        val subRoot = subQuery.from(  // not ok, the same
        throw UnsupportedOperationException()


and I have difficulty to define a reified fun:

inline fun <reified Entity> CriteriaQuery<Entity>.subquery1() = this.subquery<Entity>(


In case if you want to get java class of a reified type parameter of inline function you need to specify the upper bound of that type parameter to be Any to be able to invoke java extension property on a kotlin class. That’s how that property is declared:

val <T : Any> KClass<T>.java: Class<T>

So try the following:

inline fun <reified Entity : Any> CriteriaQuery<Entity>.subquery1()