DEV Community

Discussion on: Is there such thing as a bad programming language?

Collapse
 
tiguchi profile image
Thomas Werner • Edited

This is why Java 8 introduced Optionals. It's not syntactic sugar so it's more verbose than the Kotlin example, but it does the same thing:

String manager = Optional.ofNullable(employee)
                         .map(Employee::getDepartment)
                         .map(Department::getHead)
                         .map(Person::getName)
                         .orElse(null);
Collapse
 
calebwin profile image
Caleb Winston

Oh nice! I clearly haven't used Java in a while; I do still think the elvis operator looks a bit cleaner though.

Thread Thread
 
tiguchi profile image
Thomas Werner

Oh man... now I cannot unsee Elvis in the "Elvis operator" :-D