Kotlin默认情况下会导入哪些包/功能? [英] What packages/functions are imported by default in Kotlin?

查看:295
本文介绍了Kotlin默认情况下会导入哪些包/功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Java中,默认导入java.lang包.
在kotlin中,许多功能和类都可以不导入而使用,例如println和kotlins ArrayInt等类型.
默认情况下还会导入什么内容,并且在哪里定义?

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.*

@Magnus 指出,JS平台 查看全文

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