ManticMoo.COM All Articles Jeff's Articles
Jeffrey P. Bigham

Using instanceof in Java

Jeffrey P. Bigham

Related Ads

This is a short example of using the instanceof operator in the Java for use in the htmlparser library. It's often useful to know if a given Node variable has the runtime type of a CompositeTag or not. If it does, then you can call such methods as getTagName, but if it's a straight Node or some other subclass like a TextNode, then you can't do that!

Here's how you test:

Node my_node;

if(curr_node instanceof CompositeTag) {
  String tag_name = curr_node.getTagName();
}
Jeffrey P. Bigham
ManticMoo.COM All Articles Jeff's Articles