()
| 12 | static class Counter extends |
| 13 | HashMap<Class<? extends Pet>, Integer> { |
| 14 | Counter() { |
| 15 | super(PetCreator.ALL_TYPES.stream() |
| 16 | .map(type -> Pair.make(type, 0)) |
| 17 | .collect( |
| 18 | Collectors.toMap(Pair::key, Pair::value))); |
| 19 | } |
| 20 | public void count(Pet pet) { |
| 21 | // Class.isInstance() eliminates instanceofs: |
| 22 | entrySet().stream() |