I happen to read the following code segment from Thinking in Java
public class PetCount3 {
static class PetCounter
extends LinkedHashMap<Class<? extends Pet>,Integer> {
public PetCounter() {
super(MapData.map(LiteralPetCreator.allTypes, 0));
}
public void count(Pet pet) {
// Class.isInstance() eliminates instanceofs:
for(Map.Entry<Class<? extends Pet>,Integer> pair
: entrySet())
if(pair.getKey().isInstance(pet))
put(pair.getKey(), pair.getValue() + 1);
}
public String toString() {
StringBuilder result = new StringBuilder("{");
for(Map.Entry<Class<? extends Pet>,Integer> pair
: entrySet()) {
result.append(pair.getKey().getSimpleName());
result.append("=");
result.append(pair.getValue());
result.append(", ");
}
result.delete(result.length()-2, result.length());
result.append("}");
return result.toString();
}
}
I am quite confusing about the two specifc lines in the above code.
static class PetCounter
extends LinkedHashMap<Class<? extends Pet>,Integer>
What does LinkedHashMap<Class<? extends Pet>,Integer> mean here?
Similarily, it also has
for(Map.Entry<Class<? extends Pet>,Integer> pair
: entrySet())
How to understand the usage of <Class<? extends Pet>,Integer> and pair:entrySet() here?