0

I'm trying to iterate over a Map in Java ... it looks good to me but it's not. The error I'm getting is

Required: java.util.Map.Entry <java.lang.Integer, com.model.Horse>
Found: java.lang.Object

Here's my code

public Map loadHorses() {

    Map<Integer, Horse> horses = new HashMap<Integer, Horse>();

    // static set of horses, no reason not to hardcode them
    horses.put(1, new Horse("That Darn Gray Cat", 5, false));
    horses.put(2, new Horse("Fort Utopia", 10, false));
    horses.put(3, new Horse("Count Sheep", 9, false));
    horses.put(4, new Horse("Ms Traitour", 4, false));
    horses.put(5, new Horse("Real Princess", 3, false));
    horses.put(6, new Horse("Pa Kettle", 5, false));
    horses.put(7, new Horse("Gin Stinger", 6, false));

    return horses;
}

public void displayHorses(Map horses) {
    StringBuilder sb = new StringBuilder();
    sb.append("Horses:\n");

    for(Map.Entry<Integer, Horse> horse : horses.entrySet()){
        sb.append(horse.getKey() + ", " + horse.getValue().getName() + ", " + horse.getValue().getOdds() + ", " + horse.getValue().isWon());
    }
}

What am I doing wrong?

mortsahl
  • 602
  • 6
  • 18

0 Answers0