简体   繁体   English

Why does Android generate a Java class from my Kotlin class

[英]Why does Android generate a Java class from my Kotlin class

I'm working through a build problem.我正在解决构建问题。 Basically I have a simple Kotlin class MyClass.kt.基本上我有一个简单的 Kotlin class MyClass.kt。 It looks ok, Android studio thinks it's ok.看起来还可以,Android工作室觉得还可以。 No squiggly lines etc.没有波浪线等。

But when building I'm getting但是在建造时我得到

...\build\tmp\kapt3\stubs\debug\com\loughnane\access\MyClass.java:7: error: cannot find symbol
private ClassFromOtherModule classFromOtherModule;

When I open the class it is clearly the equivalent java code for my class except it's missing the import statement.当我打开 class 时,它显然是我的 class 的等效 java 代码,但它缺少导入语句。

I don't think anyone can really diagnose what it's not importing the class from my other module in the generated code when the kotlin code is ok.当 kotlin 代码正常时,我认为没有人能真正诊断出在生成代码中没有从我的其他模块导入 class 的原因。 But why is it generating java code in the first place?但为什么它首先会生成 java 代码? This is a pure kotlin project.这是一个纯 kotlin 项目。

Because Kotlin uses JVM (Java Virtual Machine), so basically JVM only understands Java byte code.因为Kotlin使用的是JVM(Java虚拟机),所以基本上JVM只懂ZD52387880E1EA218819A的字节码。 So, Kotlin code must be compiled to Java byte code to run, then JVM handles the rest.所以,Kotlin 代码必须编译成 Java 字节码才能运行,然后 JVM 处理 Z65E2AFC8900B8C68000

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

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