4 ms·
How does the order of evaluation work in the second form there? Will fallbackIfNullMethodCall() be evaluated even if not returned?
by cosarara 7y ago
How does the order of evaluation work in the second form there? Will fallbackIfNullMethodCall() be evaluated even if not returned?
- driver733 7y agoIt can be done this way: result = Optional.ofNullable(nullableVariable) .map(NullableType::someMethodCall) .orElseGet(() -> fallbackIfNullMethodCall());
- jeroenhd 7y agoMy code contains a bug, the code driver733 wrote is what I intended to write (usually I use predefined variables for orElse, conditionally taking the method call threw me of guard).