The REPL shows how it works: > import as JavaHashMap To avoid namespace collisions you can rename a class when you import it: import as JavaHashMap Just use a regular import declaration to import static methods and fields: > import Kotlin doesn’t have a separate import static syntax. Import statements work just like Java, with only a few differences: Or, as you’ll see in the import examples that follow, you can import the function into the scope of your other code like this: import 1 Files don’t have to contain class declarationsīecause a Kotlin file doesn’t have to contain a class, it’s perfectly legal to put one or more functions in a file: package foo.barīecause of the package name, you can now refer to the function plus1 in the rest of your code as 1. The only real difference with Java is that the package name doesn’t have to match the name of the directory that the file is in. Put package statements at the top of a file: package Functions and properties declared in object declarationsįinally, a collection of classes and functions are imported for you by default, such as kotlin.* Package statements.The import statement is not restricted to only importing class.You can rename a class when you import it.Package statements are just like Java, but they don’t have to match the directory the file is in. Import and package statements are very similar to Java, with just a few additions/improvements.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |