Given the following class:
public class EventManager
{
public void postEvent(Event event)
{
...
}
}
Is it possible to use Javassist to add overloaded methods on the fly and have them called correctly?
public void postEvent(MyEvent event)
{
...
}
I can get Javassist to add the method to the class but when I execute the following code, postEvent(Event event) is always the method that is called.
EventManager.postEvent(new MyEvent());
If I don't use Javassist and just compile the source with the added methods with the jdk it works as expected. What am I missing?
Thanks!!!
That's because which method is selected is
statically determined when the caller-side
program is compiled. This is a feature of
Java.