在Kotlin for Android中编写库是否有开销? [英] Is there an overhead for writing a library in Kotlin for Android?

查看:75
本文介绍了在Kotlin for Android中编写库是否有开销?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在考虑将Java(Android)库移植到Kotlin.我真的很喜欢Kotlin,而Java带来的好处应该可以减少库中的bug数量.

I'm considering porting a Java (Android) library to Kotlin. I really like Kotlin and the benefits over Java should reduce the number of bugs in the library.

由于该库针对的是资源受限的环境,因此我担心将库移植到Kotlin会产生额外的开销.

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

与Java库相比,Kotlin库(以.class文件分发)是否会带来任何运行时或额外的开销?

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

由于Kotlin,最终的Android应用会变大还是变慢?

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

推荐答案

Kotlin有许多专门针对Android的优化.如果通读博客文章,您会看到它如何不断减少stdlib的大小以及每个发行版中的类数.

Kotlin has many optimizations specifically that help Android. If you read through blog posts you can see how it has constantly reduced stdlib size, and amount of classes at every release.

由于Kotlin,最终的Android应用会变大还是变慢?

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

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

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

标准库非常小,其许多功能仅是内联的,这意味着它们在编译后就不存在,而只是成为内联代码. Proguard也可以照顾很多人.

Standard library is very small and many of its functions are inline-only which mean they don't exist past compilation and just become inline code. Proguard can take care of a lot as well.

由于该库针对的是资源受限的环境,我担心将库移植到Kotlin会产生额外的开销.

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很小.

You didn't define which resources are constrained. Kotlin isn't going to use more memory, not going to use more disk, and stdlib is tiny.

我真的很喜欢Kotlin,并且与Java相比,它的优点应该可以减少库中的bug数量.

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

Kotlin在Android上很受欢迎是有原因的,您应该将其视为一个标志,它有比负数更多的好处.确实,您可以通过使用Java中的一个小示例和Kotlin中的一个小示例并比较它们之间的差异来亲自看到这一点.两者都具有相同的构建管道.

Kotlin is popular on Android for a reason, and you should take that as a sign that there are many more benefits than negatives. Really you can see this for yourself by having a small example in Java and small in Kotlin and compare the difference. Proguard both, have the same type of build pipeline.

这篇关于在Kotlin for Android中编写库是否有开销?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆