What is the instanceof
operator used for? I\'ve seen stuff like
if (source instanceof Button) {
//...
} else {
//...
}
Very simple code example:
If (object1 instanceof Class1) {
// do something
} else if (object1 instanceof Class2) {
// do something different
}
Be careful here. In the example above, if Class1 is Object, the first comparison will always be true. So, just like with exceptions, hierarchical order matters!