如何解决更新到1.4.0-rc后使用stream.map时“没有足够的信息来推断类型变量R”
我有此代码段,可与Kotlin 1.3.72
一起很好地工作:
import javax.persistence.EntityManager
val query = entityManager.createQuery(...)
val myEnumToDate: MutableMap<EventTypeEnum,Date> = mutableMapOf()
query.resultStream
.map { it as Array<*> } // line 10
.map { Pair(it[0] as MyEnum,it[1] as Date) } // line 11
.forEachOrdered { (myEnum,date) -> // line 12
myEnumToDate.putIfAbsent(MyEnum,date) // line13
}
return myEnumToDate
更新到Kotlin 1.4.0-rc
后,出现以下编译错误,当使用Gradle进行编译时,IntelliJ还会在IDE中显示错误。
line 10: Not enough information to infer type variable R
line 11: Not enough information to infer type variable R
line 11: Unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
public operator fun MatchGroupCollection.get(name: String): MatchGroup? defined in kotlin.text
line 11: No get method providing array access
line 11: Unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
public operator fun MatchGroupCollection.get(name: String): MatchGroup? defined in kotlin.text
line 11: No get method providing array access
line 12: Destructuring declaration initializer of type Any! must have a 'component1()' function
line 12: Destructuring declaration initializer of type Any! must have a 'component2()' function
如何通过声明显式类型来解决它? 我认为这应该被报告为Kotlin类型干扰中的错误,对吧?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。