Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which standard library to use in Kotlin

Tags:

In Kotlin, when working with the JVM, it seems there is multiple choices for standard library, namely kotlin-stdlib, kotlin-stdlib-jdk7 and kotlin-stdlib-jdk8.

I cannot, however, find anything telling me the difference between these. The only visible difference I have found is that I cannot use com.fasterxml.jackson.databind.exc.MismatchedInputException with kotlin-stdlib, but I can with kotlin-stdlib-jdk8.

Is there anywhere I can read about the advantages using one over the others, or can anyone explain this in layman terms?

like image 949
beruic Avatar asked Aug 15 '18 12:08

beruic


1 Answers

Most of the stdlib is in the plain kotlin-stdlib artifact.

kotlin-stdlib-jdk7 adds suppressed exceptions and a few extension methods.

kotlin-stdlib-jdk8 adds ThreadLocalRandom as well as a few other extension methods and retrieving groups by name in Regexes.

The code is there: https://github.com/JetBrains/kotlin/blob/55c8b35eee2ee8a93ccaffeaac6f9c3e4fd4ff18/libraries/stdlib/jvm/src/kotlin/internal/PlatformImplementations.kt#L27

EDIT: I got curious so wrote an article about this: https://medium.com/@mbonnin/the-different-kotlin-stdlibs-explained-83d7c6bf293. Bottom line: Android declares a weird JVM version so almost nothing from -jdk7 and -jdk8 is used.

like image 170
mbonnin Avatar answered Sep 22 '22 01:09

mbonnin