简体   繁体   English

Kotlin从Java访问内部类中的常量

[英]Kotlin accessing constant in inner class from Java

NOTE : This issue has been resolved since Kotlin 1.0 beta version (at least). 注意 :自Kotlin 1.0 beta版(至少)以来,此问题已得到解决。 Keeping the rest of the contents intact for historical reason. 由于历史原因,保持其余内容完好无损。


I'm using Kotlin with Android and I'm trying to use some constants from the SDK, like this one: 我正在使用Kotlin和Android,我正在尝试使用SDK中的一些常量,如下所示:

MediaRecorder.AudioSource.MIC;

It doesn't see AudioSource, so it doesn't see the MIC as well. 它没有看到AudioSource,因此它也没有看到MIC。 I've tried changing the imports, cleaning the project. 我已经尝试更改导入,清理项目。 Nothing worked so far. 到目前为止没有任何工作。 I've temporarily solved it by importing it in a Java class, which worked just fine, and then I just refer to my Java class from my Kotlin file,but I would really like to know why this happens and how I can avoid having that Java class. 我通过在Java类中导入它来暂时解决它,它运行得很好,然后我只是从我的Kotlin文件中引用我的Java类,但我真的想知道为什么会发生这种情况以及如何避免这样做Java类。

I can confirm, accessing MediaRecorder.AudioSource.MIC doesn't work. 我可以确认,访问MediaRecorder.AudioSource.MIC不起作用。 However, if you import android.media.MediaRecorder.AudioSource manually, you can access AudioSource.MIC . 但是,如果手动导入android.media.MediaRecorder.AudioSource ,则可以访问AudioSource.MIC

我可以确认它在Kotlin Beta 4中有效,也可能在旧版本上有效。

ContactsContract.Contacts._ID

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM