Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

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

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

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

like image 285
Marc O'Morain Avatar asked Sep 22 '16 08:09

Marc O'Morain


People also ask

Is Kotlin recommended for Android?

Kotlin is an expressive and concise programming language that reduces common code errors and easily integrates into existing apps. If you're looking to build an Android app, we recommend starting with Kotlin to take advantage of its best-in-class features.

Is Kotlin good for mobile app development?

Kotlin is a modern statically typed programming language used by over 60% of professional Android developers that helps boost productivity, developer satisfaction, and code safety.

Can I use Java library in Kotlin Android?

Can I call Android or other Java language library APIs from Kotlin? Yes. Kotlin provides Java language interoperability. This is a design that allows Kotlin code to transparently call Java language methods, coupled with annotations that make it easy to expose Kotlin-only functionality to Java code.


1 Answers

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.

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

No

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

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.

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

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.

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

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.

like image 76
Jayson Minard Avatar answered Sep 27 '22 21:09

Jayson Minard