I’m trying to put both Strings and Nodes onto a Stack. I use the NodeList method item(int) to obtain a Node from the NodeList. Then, I push this Node to the Stack. My only problem is that I doesn’t see it as a Node unless I have something wrong.
When I call getClass() method on the Node and it returns this:
class com.sun.org.apache.xerces.internal.dom.DeferredElementImpl
When I call that same method on NodeList (getClass()), it returns this:
class com.sun.org.apache.xerces.internal.dom.DeepNodeListImpl
Both times when I call the getClass() method, it is before I put it on the Stack. I want to be able to any different Objects onto a Stack, and be able to filter through all the objects on the Stack to figure out which class they belong to. Thanks!
Node and NodeList are interfaces not class.
instanceofwas made for you.This code :
outputs:
You may write, after
stack.pop(),if( var instance of String )orif( var instanceof Node )… but IMHO it’s not a good idea to mix different type into a single container.