When I was trying to get an error from a hashmap with one record I kept getting null. Finally i tested it in the following way:
Iterator<Position> it = pieces.keySet().iterator();
while (it.hasNext()){
System.out.println("object from key >> " + pieces.get(it.next()));
}
Iterator<Piece> itt = pieces.values().iterator();
while (itt.hasNext()){
System.out.println("direct object >> " + itt.next().getPosition());
}
The output I got was:
object from key >> null
direct object >> application.Position@37
The code I have shown was used as it is without anything else in between.
Regarding the position object, I had overridden the hashCode() function to return the hashCode based on the values of the Position class. So when the variables within the object are changed, the HashCode is changed. The above code works well before the position object's value is changed. But once I change the I am getting a null through the key.