Say I have the following code
data.stream()
.map(x -> {
Object a = maybeReturnsNull(x);
return a == null ? defaultValue : a;
})
I have some function that might be returning null
, and I'm applying it to an element of the stream. I then want to make sure that any null
results get changed to some default value instead. Is there any significant difference between using two maps as in the following example, as compared to using the previous example that defines a helper variable a
and uses a code block in the lambda expression?
data.stream()
.map(x -> maybeReturnsNull(x))
.map(x -> x == null ? defaultValue : x)
Is there a standard on where or not to avoid using block statements with lambda functions?