kotlin包定义不用像JAVA那样匹配文件目录.
package org.example
fun printMessage() { /*...*/ }
class Message { /*...*/ }
// ...
定义package, 那么源码中的实体名为
org.example.printMessage
和org.example.Message
不定义package, 那么没有package 名
import org.example.Message // Message is now accessible without qualification
import org.example.* // everything in 'org.example' becomes accessible
// 处理包名冲突
import org.example.Message // Message is accessible
import org.test.Message as testMessage // testMessage stands for 'org.test.Message'
import
可以不止导入类, 也可以导入:
- top-level functions and properties
- functions and properties declared in object declarations
- enum constants
If a top-level declaration is marked private, it is private to the file it’s declared in (see Visibility modifiers).