With Android projects, Kotlin is compiled to Java bytecode that runs on Dalvik Virtual Machine (before Android 5.0) or Android Runtime (Android 5.0 and newer). Both virtual machines can execute only the code that is defined inside a class. To solve this problem, the Kotlin compiler generates classes for top-level functions. The class name is constructed from the file name and the Kt
suffix. Inside such a class, all functions and properties are static. For example, let's suppose that we define a function within the Printer.kt
file:
// Printer.kt fun printTwo() { print(2) }
Kotlin code is compiled into Java bytecode. The generated bytecode will be analogical to the code generated from the following Java class:
//Java public final class PrinterKt { // 1 public static void printTwo() { // 2 System.out.print(2); // 3 } }
PrinterKt
is the name made from the name of the file and theKt
suffix.
- All...