|
|
|
|
|
by krzyk
3431 days ago
|
|
> "If something is wrong, throw an exception." > That is sometimes just not an option performance wise yet. Why? I haven't heard about performance issues of exceptions since 90-ties and C++ problems. And if you consider that you can throw exceptions instead of error codes (which null is an example of) why would a list of numbers be ever null? It should be an empty list, not null. Generally you don't add Optionals to Collections/Iterables/Maps because they already have a notion of empty. So your example becomes: List<Integer> nums = getNumbers();
for (Integer i : nums)
System.out.println(i);
And if getNumbers has an error, it should throw an exeption. |
|