October 2019
Intermediate to advanced
434 pages
11h 54m
English
Using the @JvmName annotation to control how generated classes are named works for features such as top-level properties and extension functions as well. In the following code snippet, we've declared a top-level property named screenCount:
// Constants.ktvar screenCount = 0
We can then reference screenCount from Java by referencing the default class name that's generated; in this case, this is ConstantsKt:
// Main.javapublic class Main { public static void main(String[] args) { GreetingsHelper.sayHello("Nate"); ConstantsKt.getScreenCount(); }}
By adding the @JvmName annotation, we can change the generated class name from ConstantsKt to Constants:
@file:JvmName("Constants")// Constants.kt ...
Read now
Unlock full access