Class<? extends Foo> dynamicType = new ByteBuddy()
.subclass(Foo.class)
.method(named("sayHello"))
.intercept(FixedValue.value("Hello Byte Buddy Agent!"))
.make()
.load(Foo.class.getClassLoader())
.getLoaded();
Foo foo = dynamicType.getDeclaredConstructor().newInstance();
System.out.println(foo.sayHello());
public static void premain(String agentArgs, Instrumentation instrumentation) {
new AgentBuilder.Default()
.type(ElementMatchers.any())
.transform((builder, type, classLoader, module) ->
builder.method(named("sayHello"))
.intercept(FixedValue.value("Hello Byte Buddy Agent!")))
.installOn(instrumentation);
}