1. From Kotlin code to the JVM

[THEORY]

[PREDICT]

Read the code carefully before you run it.

prediction.kt
// File: Utils.kt
package de.firma.tools

fun square(x: Int): Int = x * x

class Calculator {
    fun double(x: Int): Int = x * 2
}

How many .class files does the Kotlin compiler produce from this one Utils.kt, and what are they called?

[TASK]

AppConfig.kt contains only top-level declarations. Java code currently has to call them through AppConfigKt.loadConfiguration() — after all, the generated class is named after the file plus "Kt". Use a file annotation to make the generated class be called AppConfig instead, without renaming the file or moving the code into a real class.

task.kt
// TODO: add the annotation so the generated class is named "AppConfig" instead of "AppConfigKt" package de.firma.konfiguration const val MAX_ATTEMPTS = 3 fun loadConfiguration(): String = "Standard configuration"

Before you get a hint: what have you tried, and where exactly are you stuck?

[COMPREHENSION CHECK]

1. Why can Java code call Kotlin top-level functions at all, although the JVM knows no "free" functions outside classes?

2. What does the JIT compiler (Just-in-Time) do when the JVM recognizes a method as "hot" (executed often)?

3. A file Utils.kt contains a top-level function square() AND a class Calculator. How many .class files does the Kotlin compiler produce from that, and what are they called?