Interoperability and Nullity

Add another method to Jhava called determineFriendshipLevel. determineFriendshipLevel should return a value of type String and, because the monster does not understand friendship, a value of null.

Listing 20.4  Returning null from a Java method (Jhava.java)

public class Jhava {
    public String utterGreeting() {
        return "BLARGH";
    }

    public String determineFriendshipLevel() {
        return null;
    }
}

Call this new method from Hero.kt, storing the monster’s friendship level in a val. You are going to print this value out to the console, but, remembering that the monster yelled its greeting at you in all caps, go ahead and lowercase the friendship level before printing it out.

Listing 20.5  Printing the friendship ...

Get Kotlin Programming: The Big Nerd Ranch Guide, First Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.