Android 在 Kotlin 中编写库是否有开销?

Is there an overhead for writing a library in Kotlin for Android?

我正在考虑将 Java (Android) 库移植到 Kotlin。我真的很喜欢 Kotlin 并且 Java 的好处应该会减少库中的错误数量。

由于库的目标是资源受限的环境,我担心将库移植到 Kotlin 会产生额外的开销。

与 Java 库相比,Kotlin 库(作为 .class 文件分发)是否会引入任何运行时或额外开销?

生成的 Android 应用程序是否会因为 Kotlin 而变大或变慢?

Kotlin 有许多专门帮助 Android 的优化。如果您通读博文,您会发现它如何不断减小 stdlib 的大小,以及每次发布时 类 的数量。

Will the resulting Android app be any larger or slower because of Kotlin?

没有

Does a Kotlin library (distributed as .class files) introduce any runtime or extra overhead versus a Java library?

标准库非常小,它的许多函数都是内联的,这意味着它们在编译后不存在,只是成为内联代码。 Proguard 也可以处理很多事情。

Since the library is targeting a resource constrained environment I'm worried that by porting the library to Kotlin there will be extra overhead.

您没有定义哪些资源受到限制。 Kotlin 不会使用更多内存,不会使用更多磁盘,而且 stdlib 很小。

I really like Kotlin and the benefits over Java should reduce the number of bugs in the library.

Kotlin 在 Android 上的流行是有原因的,您应该将其视为优点多于缺点的标志。实际上,您可以通过 Java 中的小示例和 Kotlin 中的小示例来亲眼看到这一点,并比较差异。 Proguard 两者,具有相同类型的构建管道。

上面 5747 的 link 进入了一个色情网站,应该被删除。

“有 Kotlin 标准库,它的方法数约为 5747,但如果客户端仍然使用 stdlib,这可能无关紧要。– 纳尔曼 2016 年 9 月 22 日 8:56