I was reading an InfoWorld article, and came across this little tidbit:

Take the latest version of Java, which tries to make null-pointer checking easier by offering shorthand syntax for the endless pointer testing. Just adding a question mark to each method invocation automatically includes a test for null pointers, replacing a rat's nest of if-then statements, such as:

public String getPostcode(Person person) {
    String ans = null;
    if (person != null) {
        Name nm = person.getName();
        if (nm != null) {
            ans = nm.getPostcode();
        }
    }
    return ans;
}

With this:

public String getFirstName(Person person) {
    return person?.getName()?.getGivenName();
}

I've scoured the internet and got nothing. So, my question: is there any official documentation on this? Or, is this just a use of the ternary operator that I've never seen before?

I found that C# has a similar operator, the ?? operator, but I'd like to get the documentation for the language I'm working in.

Edit
Report