Closed GoogleCodeExporter closed 9 years ago
Why, though? The first version seems more readable, shorter, more efficient...
Original comment by lowas...@google.com
on 11 Dec 2013 at 7:14
I agree it's shorter and more efficient. However the firstNonNull is a bit
better readability-wise.
It also aligns with the concept of non-null collections, so if we were to
example the snippet.
public foo(@Nullable Collection input) {
Collection collection = Objects.firstNonNull(input, Collections.EMPTY_LIST);
if (!collection.isEmpty()) {
// some-logic
}
}
Original comment by tj.rothw...@gmail.com
on 11 Dec 2013 at 7:23
I strongly disagree that the firstNonNull version is better readability-wise...
it's much less clear about what it's actually doing. And I don't agree that it
aligns with avoiding null collections because the whole point of that is to
actually assign something as a non-null collection so you can avoid checking
for null in future calls (as in your example above). When you just immediately
call isEmpty(), that's not happening.
Original comment by cgdecker@google.com
on 11 Dec 2013 at 7:27
This issue has been migrated to GitHub.
It can be found at https://github.com/google/guava/issues/<issue id>
Original comment by cgdecker@google.com
on 1 Nov 2014 at 4:10
Original comment by cgdecker@google.com
on 3 Nov 2014 at 9:08
Original issue reported on code.google.com by
tj.rothw...@gmail.com
on 11 Dec 2013 at 7:12