Kotlin默认情况下会导入哪些包/功能? [英] What packages/functions are imported by default in Kotlin?
问题描述
在Java中,默认导入java.lang
包.
在kotlin中,许多功能和类都可以不导入而使用,例如println
和kotlins Array
,Int
等类型.
默认情况下还会导入什么内容,并且在哪里定义?
In Java the java.lang
package is imported by default.
In kotlin a number of functions and classes are available without being imported, like println
and kotlins Array
, Int
, etc types.
What else is imported by default and where is it defined?
推荐答案
Kotlin stdlib具有kotlin
根软件包及其子软件包(请参阅包含内容的完整列表).
Kotlin stdlib has kotlin
root package and its subpackages (see the full list with the content).
It seems not to be documented anywhere which of them are imported by default, but a peek into Kotlin Github sources suggests that these packages are imported for JVM target platform:
-
java.lang.*
-
kotlin.*
-
kotlin.annotation.*
-
kotlin.jvm.*
-
kotlin.collections.*
-
kotlin.ranges.*
-
kotlin.sequences.*
-
kotlin.text.*
-
kotlin.io.*
-
kotlin.coroutines.*
(将在Kotlin 1.1中添加,在1.0.4中不存在)
java.lang.*
kotlin.*
kotlin.annotation.*
kotlin.jvm.*
kotlin.collections.*
kotlin.ranges.*
kotlin.sequences.*
kotlin.text.*
kotlin.io.*
kotlin.coroutines.*
(to be added in Kotlin 1.1, not present in 1.0.4)
我已经对其进行了手动测试,并且上面的列表适用于Kotlin 1.0.4.这些stdlib软件包默认情况下不导入:
I've manually tested them, and the list above is true for Kotlin 1.0.4. And these stdlib packages are not imported by default:
-
kotlin.comparisons.*
-
kotlin.concurrent.*
-
kotlin.properties.*
-
kotlin.reflect.*
-
kotlin.reflect.jvm.*
-
kotlin.system.*
kotlin.comparisons.*
kotlin.concurrent.*
kotlin.properties.*
kotlin.reflect.*
kotlin.reflect.jvm.*
kotlin.system.*