当前位置: 首页 > 知识库问答 >
问题:

类型不匹配:推断的类型是KClass,但Class!预料之中

仉伟兆
2023-03-14

我试图构建查询投影,我遇到了以下错误消息:

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)

方法项目需要类型Class

性别统计的定义如下:

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

共有1个答案

公冶同
2023-03-14

试着改变

GenderStatistics::class 

GenderStatistics::class.java
 类似资料: