[jdom-interest] Element instanceof stacks

Les Hill leh at galaxynine.com
Fri Apr 19 15:44:54 PDT 2002

elharo at metalab.unc.edu wrote:
>arosen at silverstream.com wrote:
> >... assuming that they recompile. But if they just drop in the new
> >and don't recompile all their calling classes, I think that it won't
> >right?
> I'm not sure. Java binds pretty late relative to other languages, so
> I think the actual method might be chosen at runtime, but I'm not
> sure. If it's a problem we can deprecate for a beta cycle, and remove
> them later.

Alex is right.  Methods are selected at compile time (which method signature
to use), but invoked on objects at runtime (which object has the method
called).  This is why you cannot do something like:

    Object obj = mylist.get(x);

where doSomething() has n different signatures (none of them Object :).
This will generate a compile time error since the compiler cannot find a
valid method.  On the other hand, something like:

    Base obj= (Base)mylist.get(indexOfSub);

will compile and will call doSomething() on a subclass of Base if that is
the actual type of the obj object.

Les Hill
leh at galaxynine.com

More information about the jdom-interest mailing list