|
|
|
|
|
by ebola1717
3431 days ago
|
|
In practice, your first example would be more likely to look like: public List<Integer> add2(File file) {
List<Integers> nums = file.getNumbers();
if(nums != null) {
List<Integer> resultList = List<>();
for ( i : nums) {
resultList.append(i + 2);
}
return resultList;
} else {
return null;
}
}
Compare that to: public Optional<List<Integer>> add2(File file) {
Optional<List<Integers>> numsOpt = file.getNumbers();
return numsOpt.map((nums) =>
nums.map((i) => i + 2);
);
}
I find it hard to argue that the latter is worse. |
|