Calling static Java methods from Kotlin

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 method
public 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.logMessage
fun main(args: Array<String>) {
val kotlinDev = Developer("Your Name", "Kotlin")
val name = kotlinDev.getName()

Logger.logMessage(name)
}

The logMessage method can be called from Kotlin code the same way as it would be from Java. This is particularly interesting because Kotlin does not have the static keyword, and therefore does not have static methods or fields in the same way Java does. You'll learn more about Kotlin's lack of static, and its impact on your code, iChapter 5Modeling Real-World Data, and Chapter 7Crossing Over – Working across Java and Kotlin.