Type-Casting Object doesn't Give me the Methods I need
I am slightly stuck and I would greatly appreciate any help.
I have a Node class, and this class has several methods, one of which is [ getName() ] which returns a String that represents the name of the node.
Here is my code:
A couple of things are happening here (I hope you can see), but the gist of it is that I am iterating through a Hashtable.
// A place to store the safe paths.
ArrayList<Stack<String>> paths = new ArrayList<Stack<String>>();
// The variable g stands for, and is the Graph object < which in itself is a Hashtable.
Hashtable<Node<Adjustment>, ArrayList<Node<Adjustment>>> g = getMap().getAdjacencyList();
// Iterating through [g] to find safe paths.
Enumeration e = g.keys();
// A variable called [neighbours]. It represents the neighoubrs of the current node in the loop
ArrayList<Node<Adjustment>> neighbours = g.get((Node<Adjustment>)e.nextElement());
// The Path [p] represented as a Stack. This will be inserted into our safe [paths] ArrayList later on.
Stack<String> p = new Stack<String>();
// Iterating through the neighbours of the current node, and foreach building a path [p] from them.
for(Node n : neighbours)
e.nextElement() is an object. I am type casting it to a Node<Adjustment> but it isn't working. How do I know it isn't working ? .. It isn't giving me my getName() method.
What am I doing wrong ? I would greatly appreciate any help.