3 ms·
Would this work? return Optional.ofNullable(nullableVariable).map(v -> v.someMethodCall()).orElse(false) ? true : fallbackIfNullMethodCall();
by RyEgswuCsn 7y ago
Would this work?
return Optional.ofNullable(nullableVariable).map(v -> v.someMethodCall()).orElse(false) ? true : fallbackIfNullMethodCall();
- AnyTimeTraveler 7y agoWhy not replace the tenary operator at the end with the method call in the or else block? return Optional.ofNullable(nullableVariable) .map(v::someMethodCall) .orElse(fallbackIfNullMethodCall); That also looks much easier to understand, at least to me.