Creating and working with Kotlin classes from Java

The following snippet illustrates our simple Developer class written in Kotlin:

// simple Kotlin class with 2 properties and associated getters
data class Developer(
val name: String,
val favoriteLanguage: String
)

In the following, you can see how the Developer class written in Kotlin can be used from a Java method:

public class KotlinFromJava {
public static void main(String[] args) {
Developer developer = new Developer("Your Name", "Kotlin");
String name = developer.getName();
}
}

The new instance of Developer is created like any other Java class, and its properties are available via generated getters even though they weren't defined in the Kotlin code. You'll learn more about how this works in Chapter 5Modeling Real-World Data.