First of all, define callFriend:
public <T extends Animal> T callFriend(String name, Class<T> type) {
return type.cast(friends.get(name));
}
Then call it as such:
jerry.callFriend("spike", Dog.class).bark();
jerry.callFriend("quacker", Duck.class).quack();
This code has the benefit of not generating any compiler warnings. This is really just an updated version of casting from the pre-generic days and doesn't add any additional safety.