instanceof

java: combined instanceof and cast ?

(Please no advise that I should abstract X more and add another method to it.) In C++, when I have a variable x of type X* and I want to do something specific if it is also of type Y* (Y being a subclass of X), I am writing this: if(Y* y = dynamic_cast<Y*>(x)) { // now do sth with y } The same thing seems not possible in Java (or...

Dynamically load a class in JAVA- Anomaly

Guys, I have got a slightly different problem with Java Dynamic class loading. I have to pass an object( lets say Object A1 of class A) to the constructor of a different object B1 of class B, So that the A1's details are stored inside B1. B1 does not know what kind of object it is receiving. So all it knows is that A1 is an object. N...

Should I avoid instanceof when working with a tree of objects?

I have a class hierarchy representing different language constructs: Expression <- NumericLiteral UnaryExpression BinaryExpression IndexingExpression IteratedExpression ... The objects of these classes form complex tree hierarchies on which I have to perform va...