在Kotlin中使用哪个标准库 [英] Which standard library to use in Kotlin
问题描述
在Kotlin中,使用JVM时,标准库似乎有多种选择,分别是kotlin-stdlib
,kotlin-stdlib-jdk7
和kotlin-stdlib-jdk8
.
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
.
但是,我找不到任何能告诉我两者之间差异的信息.
我发现的唯一可见区别是我不能将com.fasterxml.jackson.databind.exc.MismatchedInputException
与kotlin-stdlib
一起使用,但是可以与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?
推荐答案
顾名思义,在使用JDK8时应使用-jdk8.它包含用于将JDK 8中所做的更改集成到Kotlin标准库中的代码.
As the name indicates, -jdk8 is supposed to be used when using the JDK8. It contains code used to integrate the changes made in the JDK 8 into the Kotlin standard lib.
如pom所示,它依赖于-jdk7,该代码包含将JDK 7中所做的更改集成到Kotlin标准库中所需的代码.
As its pom indicates, it depends on -jdk7, which contains the code needed to integrate the changes made in the JDK 7 into the Kotlin standard lib.
-jdk7的pom表示,它取决于stdlib.
And as the pom of -jdk7 indicates, it depends on the stdlib.
因此,简而言之,请使用与您的JDK匹配的一个.将其添加到依赖项中还将通过传递方式添加JDK早期版本中的所有依赖项.
So, in short, use the one matching your JDK. Adding it to the dependencies will also, transitively, add all the ones for the previous versions of the JDK.
这篇关于在Kotlin中使用哪个标准库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!