October 2019
Intermediate to advanced
434 pages
11h 54m
English
Now let's look at another example of working with Java from Kotlin. In the following snippet, you'll see a simple Java class named Logger. This class has a single, static method named logMessage:
// simple Java class with static methodpublic class Logger { public static void logMessage(String message) { System.out.println(message); }}
Now see how the Java method can be used from Kotlin to print the name from the Developer object created in the previous example:
// Kotlin function calling the static Java method Logger.logMessagefun main(args: Array<String>) { val kotlinDev = Developer("Your Name", "Kotlin") val name = kotlinDev.getName() Logger.logMessage(name)}
The logMessage method can be called from ...
Read now
Unlock full access