【问题标题】:Type mismatch: inferred type is KClass<GenderStatistics> but Class<TypeVariable(T)!>! was expected类型不匹配:推断类型是 KClass<GenderStatistics> 但 Class<TypeVariable(T)!>!预计
【发布时间】:2020-10-23 19:56:57
【问题描述】:

我正在尝试构建Query Projection,但遇到以下错误消息:

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&lt;TypeVariable(T)!&gt;! 类型,但我传递了错误的类型。如何在 Kotlin 中传递正确的类型?在 Java 中,它将是 GenderStatistics.class

GenderStatistics 定义为:

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

【问题讨论】:

  • 如果你使用GenderStatistics::class.java传递java类而不是kotlin KClass,它是否有效,或者即使这样做了还有进一步的问题?

标签: java hibernate kotlin quarkus-panache


【解决方案1】:

尝试改变

GenderStatistics::class 

GenderStatistics::class.java

【讨论】:

    猜你喜欢
    • 2021-09-15
    • 1970-01-01
    • 1970-01-01
    • 2020-03-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-16
    相关资源
    最近更新 更多