[英]Why are new Android features (Proto DataStore) still generating Java code and Not Kotlin?
I'm investigation我在调查
implementation "androidx.datastore:datastore-core:1.0.0-alpha01"
implementation "com.google.protobuf:protobuf-javalite:3.10.0"
I do not understand why the associated DataStore generated classes are Java我不明白为什么关联的 DataStore 生成的类是 Java
I thought Google announced that Kotlin had replaced Java as the primary Android development language?我以为 Google 宣布 Kotlin 已经取代 Java 成为主要的 Android 开发语言?
I was under the impression Kotlin had many advantages over Java我的印象是 Kotlin 比 Java 有很多优势
is the issue proto buffers do not support Kotlin?问题是 proto 缓冲区不支持 Kotlin 吗?
I can answer that quickly!我可以这么快回答!
According to codelab link you shared, If you visit page 6 first line indicates something where your answer relies:根据您共享的 codelab 链接,如果您访问第 6 页,第一行表示您的答案所依赖的内容:
Protocol buffers are a mechanism for serializing structured data.
协议缓冲区是一种用于序列化结构化数据的机制。 You define how you want your data to be structured once and then the compiler generates source code to easily write and read the structured data.
您可以一次定义数据的结构方式,然后编译器生成源代码以轻松编写和读取结构化数据。
So, basically under the hood, library is using code generator plugin that generates classes required for protobuf to work with project.因此,基本上在幕后,库正在使用代码生成器插件来生成 protobuf 与项目一起工作所需的类。 (Yes, you can relate same thing with data-binding where you write code on xml and under the hood there's generated class that actually implements that logic for you)
(是的,您可以将相同的事情与数据绑定联系起来,您可以在 xml 上编写代码,并且在后台生成的类实际上为您实现了该逻辑)
And that's the reason 'generated classes are in Java'.这就是“生成的类在 Java 中”的原因。 It has nothing to do with source in this context (Java/Kotlin support to library) .
它与此上下文中的源无关(Java/Kotlin 对库的支持) 。 Anything written in Java will seamlessly work on Kotlin and vice versa (Considering Android development context)
任何用 Java 编写的东西都可以在 Kotlin 上无缝运行,反之亦然(考虑 Android 开发环境)
Side note: You can also relate it to annotation processor where we actually generate Java code based on annotation on any criteria.旁注:您还可以将其与注解处理器相关联,在该处理器中我们根据任何标准的注解实际生成 Java 代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.