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

huangapple go评论65阅读模式
英文:

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

问题

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

类型不匹配:推断类型为KClass<GenderStatistics>,但期望的类型是Class<TypeVariable(T)!>

导致问题的代码:

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)
英文:

I am trying to build Query Projection and I have encountered the following error message:

Type mismatch: inferred type is KClass&lt;GenderStatistics&gt; but Class&lt;TypeVariable(T)!&gt;! was expected

the code that is causing the problem:

  fun status(): String {
    val query = accRepo.find(&quot;&quot;&quot;
      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
      &quot;&quot;&quot;.trimIndent())
        .project(GenderStatistics::class)

The method project expects type Class&lt;TypeVariable(T)!&gt;! but I have passed wrong type. How to pass the correct type in Kotlin? In Java, it will be GenderStatistics.class

The GenderStatistics is defined as:

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

答案1

得分: 4

尝试将

GenderStatistics::class 

更改为

GenderStatistics::class.java
英文:

try changing

GenderStatistics::class 

to

GenderStatistics::class.java

huangapple
  • 本文由 发表于 2020年10月24日 03:56:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/64506550.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定