英文:
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<GenderStatistics> but Class<TypeVariable(T)!>! was expected
the code that is causing the problem:
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)
The method project
expects type Class<TypeVariable(T)!>!
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论