Interoperating with a Java Class
For this chapter, create a new project in IntelliJ called Interop. Interop will contain two files: Hero.kt, a Kotlin file that represents the hero from NyetHack, and Jhava.java, a Java class that represents a monster from another realm. Create these two files as well.
In this chapter, you will write both Kotlin code and Java code. If you do not have experience writing Java code, fear not, as the Java code in these examples should be intuitive given your Kotlin experience.
Start by declaring the Jhava class and giving it a method called utterGreeting that returns a String:
Listing 20.1 Declaring a class and method in Java (Jhava.java)
public class Jhava {
public String utterGreeting() {
return ...Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access