Skip to Main Content

Java HotSpot Virtual Machine

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interpositioning in Java

843811Jan 5 2004 — edited Jan 7 2004
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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 4 2004
Added on Jan 5 2004
8 comments
291 views