Umm... I'm having trouble with the piece of code below. I've been trying for hours and still couldn't get it to run properly.
Iterator iter = this.iterator();
while (iter.hasNext()) {
Node currentNode = (Node) iter.next();
City currentCity = (City) (currentNode.getValue());
}
currentNode.getClass() returns class Node as expected. getValue() returns an Object. currentNode.getValue().getClass() returns a class City, also as expected.
But the problem is, City currentCity = (City) (currentNode.getValue()); returns the following runtime error:
Exception in thread "main" java.lang.ClassCastException: java.lang.String
Is there something obvious I'm not aware of that someone could point out? Thanks.