Hi,
I was wondering if there was any way to interpose new classes and/or methods into a pre-existing java application? Specifically, if I have a set of class files that I have no source for, how can I reroute calls to methods in those objects to methods I have written myself? I'm looking for an equivalent of the LD_PRELOAD method of interposing in C, where I do not need to modify any code at all, just add my own code. For example, if I have an application that calls doodad.method1(), I want to insert a new object that looks like this:
class doodad {
private realdoodad realobj;
doodad(args) {
this.realobj=new realdoodad(args);
}
int method1() {
System.out.println("method1 called");
return realobj.method1();
}
}
Is there any way to do this?
Regards
James