gpt4 book ai didi

Kotlin Foo::class.java "Unresolved Reference: Java"错误

转载 作者:IT老高 更新时间:2023-10-28 13:28:54 27 4
gpt4 key购买 nike

我正在尝试将 HomePage.class 的 Java 代码转换为 Kotlin。我按照 Kotlin.org 上的说明进行操作:

getClass()

To retrieve the type information from an object, we use the javaClass extension property.

val fooClass = foo.javaClass

Instead of Java’s Foo.class use Foo::class.java.

val fooClass = Foo::class.java

我有一个名为 HomePage 的类,它扩展了 AppCompatActivity(在 Android 中)。我正在使用安卓工作室。我尝试做 HomePage::class.java 并且它有一个错误:Unresolved reference: java

enter image description here

如何让它工作?

最佳答案

问题很可能是您忘记依赖 reflection libraries这是 Kotlin 的反射功能所需要的。

On the Java platform, the runtime component required for using the reflection features is distributed as a separate JAR file (kotlin-reflect.jar). This is done to reduce the required size of the runtime library for applications that do not use reflection features. If you do use reflection, please make sure that the .jar file is added to the classpath of your project.

Source

关于Kotlin Foo::class.java "Unresolved Reference: Java"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34144392/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com