Slide 23
Slide 23 text
switchで条件分岐
●
switchで条件分岐
var cart = List.of(
new Item(new Packed(300), 3),
new Item(new Bulk(250, 100), 230));
int total = cart.stream()
.mapToInt(item -> switch(item) {
case Item(Packed(int price), int amount)
-> price * amount;
case Item(Bulk(int price, int unit), int amount)
-> price * amount / unit;
}).sum();