The website uses cookies to optimize your user experience. Using this website grants us the permission to collect certain information essential to the provision of our services to you, but you may change the cookie settings within your browser any time you wish. Learn more
I agree
Text direction?


A source file may start with a package declaration:

package foo.bar

fun baz() { ... }
class Goo { ... }

// ...

All the contents (such as classes and functions) of the source file are contained by the package declared. So, in the example above, the full name of baz() is foo.bar.baz, and the full name of Goo is foo.bar.Goo.

If the package is not specified, the contents of such a file belong to "default" package that has no name.

Default Imports

A number of packages are imported into every Kotlin file by default:

Additional packages are imported depending on the target platform:


Apart from the default imports, each file may contain its own import directives. Syntax for imports is described in the grammar.

We can import either a single name, e.g.

import foo.Bar // Bar is now accessible without qualification

or all the accessible contents of a scope (package, class, object etc):

import foo.* // everything in 'foo' becomes accessible

If there is a name clash, we can disambiguate by using as keyword to locally rename the clashing entity:

import foo.Bar // Bar is accessible
import bar.Bar as bBar // bBar stands for 'bar.Bar'

The import keyword is not restricted to importing classes; you can also use it to import other declarations:

Unlike Java, Kotlin does not have a separate "import static" syntax; all of these declarations are imported using the regular import keyword.

Visibility of Top-level Declarations

If a top-level declaration is marked private, it is private to the file it's declared in (see Visibility Modifiers).

Related Notes
Get a free MyMarkup account to save this article and view it later on any device.
Create account

End User License Agreement

Summary | 3 Annotations
import bar.Bar as bBar // bBar stands for 'bar.Bar'
2017/09/16 15:27
a, Kotlin does not have a separate "import static" syntax;
2017/09/16 15:29
Unlike Java
2017/09/16 15:29