0

我正在尝试构建查询投影,但遇到以下错误消息:

Type mismatch: inferred type is KClass<GenderStatistics> but Class<TypeVariable(T)!>! was expected

导致问题的代码:

  fun status(): String {
    val query = accRepo.find("""
      select g.abbr as abbr, g.description as description, count(p) as quantity
        from Account a
        inner join a.gender as g
        group by g.abbr, g.description
      """.trimIndent())
        .project(GenderStatistics::class)

该方法project需要类型Class<TypeVariable(T)!>!,但我传递了错误的类型。如何在 Kotlin 中传递正确的类型?在 Java 中,它将是GenderStatistics.class

GenderStatistics定义为:

@RegisterForReflection
class GenderStatistics(val abbr: String, val description: String, val quantity: Int)
4

1 回答 1

2

尝试改变

GenderStatistics::class 

GenderStatistics::class.java
于 2021-03-31T10:37:28.313 回答