I'm using Guava's Optional
and I want to return Optional.absent()
when string is empty or Optional.of(name)
when string is not empty. Can I do it in some concise form without using ternary operator? Here's my current code:
final String name = getName();
final Optional<String> optional;
if (name.isEmpty()) {
optional = Optional.absent();
} else {
optional = Optional.of(name);
}