通过“懒惰"和“对象"的组合导致编译器错误“找不到符号". [英] Combining `by lazy` and `object` results in compiler-error "cannot find symbol"

查看:89
本文介绍了通过“懒惰"和“对象"的组合导致编译器错误“找不到符号".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用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"
        }
    }
}

一旦我组合了objectby 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.java:9:错误:找不到符号
私人最终my.package.Test $ foo $ 2 $ 1 getFoo()

Test.java:9: error: cannot find symbol
private final my.package.Test$foo$2$1 getFoo()

符号:类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

这篇关于通过“懒惰"和“对象"的组合导致编译器错误“找不到符号".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆