Skip to content
Discussion options

You must be logged in to vote

Here's how you can use Java Instrumentation to intercept and modify the behavior of the Foo class:

Create an agent class that implements the java.lang.instrument.ClassFileTransformer interface. In this class, you can redefine the Foo class.

import java.lang.instrument.ClassFileTransformer; import java.lang.instrument.Instrumentation; import java.security.ProtectionDomain; import javassist.*;

public class FooAgent implements ClassFileTransformer {
public static void premain(String agentArgs, Instrumentation inst) {
inst.addTransformer(new FooAgent());
}

@Override
public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined,
                        ProtectionD…

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@NadChel
Comment options

@mamoon-rasheed
Comment options

Answer selected by NadChel
@NadChel
Comment options

@mamoon-rasheed
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Programming Help Discussions around programming languages, open source and software development
2 participants