问题描述
尝试使用by lazy
和 object
时,更新到Kotlin 1.3.0(在1.2.71 中工作)后,我无法编译.这似乎仅在我的项目中发生.一个演示项目运行正常.
I cannot compile anymore after the update to Kotlin 1.3.0 (works in 1.2.71) when trying to use by lazy
and object
. This seems to happen only on my project. A demo-project is working fine.
我想将接口添加到给定的类并延迟加载其值.
I want to add an interface to a given class and lazy-load its values.
我创建了一个小示例,该示例在我的项目中不起作用,但是在其他任何项目中都可以正常工作:
I've created a small example which is not working in my project but working fine in any other:
open class Foo
interface Bar {
val lazyLoadedString : String
}
class Test {
private val foo by lazy {
object : Foo(), Bar {
override val lazyLoadedString = "Demo"
}
}
}
一旦我组合了object
和by lazy
,它就不能再编译并显示以下错误.单独使用每个人都是有效的.
As soon as I combine object
and by lazy
, it cannot compile anymore and shows the following error. Using each one alone works.
符号:类Test $ foo $ 2 $ 1
位置:打包my.package
symbol: class Test$foo$2$1
location: package my.package
近距离查看时,您会看到生成的Java文件显示此错误,而不是kotlin代码.
When looking closer, you'll see that the generated java file shows this error and not the kotlin-code.
对此有何想法?
推荐答案
对于这种特定类型的代码,kapt似乎在Kotlin 1.3.0中已被破坏.
It looks like kapt is broken in Kotlin 1.3.0 for this particular kind of code.
在上面的代码中,触发它的是Realm注册的注释处理器,但是任何其他注释处理器都将导致相同的错误.
In the code above, it was the annotation processor registered by Realm that triggered it, but any other annotation processor would have resulted in the same error.
此问题已在此处跟踪: https://youtrack.jetbrains.net/issue/KT-28053
The issue is being tracked here: https://youtrack.jetbrains.net/issue/KT-28053
这篇关于通过“懒惰"和“对象"的组合导致编译器错误“找不到符号".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!