|
|
Using instanceof in JavaJeffrey P. Bigham |
|
Related ArticlesRelated 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();
}
|
|
|
|
||