w********m 发帖数: 1137 | 1 习惯用java8的lambda,stream
不知道面试会不会被歧视 | n**********r 发帖数: 43 | 2 我觉得不太好,因为写白板时常会有修改,
如果一次性写完没有修改的话有利,比如简单的print。
但如果稍微有些复杂的话,Lamada很多时候需要毁了重来,
而白板上不能上下调整,所以follow up会很被动。下面的例子,
哪个更容易懂?哪个更适合变化?
List costBeforeTax = Arrays.asList(100, 200, 300, 400, 500);
double total = 0;
for (Integer cost : costBeforeTax) {
double price = cost + .12*cost;
total = total + price;
}
List costBeforeTax = Arrays.asList(100, 200, 300, 400, 500);
double bill = costBeforeTax.stream().map((cost) -> cost + .12*cost).reduce((
sum, cost) -> sum + cost).get(); | w********m 发帖数: 1137 | 3 多谢大牛!
看来我还是用old plain Java syntax好了 |
|