我在Kotlin工作,想读取实体列表,但是在{}上遇到语法错误:“类型不匹配,必填:类型!,找到的:()->单位”
如果删除{},则语法错误在GenericType上:“无法访问'init',它在GenericType中 protected ”
我想知道从Kotlin的响应中读取实体列表的正确语法是什么
val path = URL_PATH
val target = getTarget(path)
val response = getRequestBuilder(target).get()
response.readEntity(GenericType<List<FoodSummary>>() {})
最佳答案
这应该工作:
response.readEntity(object : GenericType<List<FoodSummary>>() {})
检查以下内容以获取更多详细信息:How to create an instance of anonymous class of abstract class in Kotlin?
关于rest - JAX-RS如何在Kotlin中读取列表的实体响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51410965/