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 (

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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.