We can easily instantiate Java classes from Kotlin and Kotlin classes from Java. In this snippet, we've used Kotlin to define a Person class with two public properties:
open class Person(val firstName: String, val lastName: String)
Here, we can see that we can instantiate an instance of the Person class from Java, like we would any other Java class:
public static void main(String[] args) {
Person person = new Person("John", "Smith");
}
Note that when instantiating Person from Java, it's still necessary to use the new keyword, so even though the class is defined in Kotlin, we must still adhere to the Java syntax rules when consuming Person from Java.
Not only can we consume classes across language boundaries, but classes defined in Java can be extended from Kotlin and vice versa. We'll take a look at this in the next section.