interface Foo{
Object foo(Object... args);
}
static class FooAdapter{
Object foo2(String msg, Integer age) {
System.out.println(msg+"=>"+age);
return age;
}
}
public static void main(String[] args) throws Exception{
FooAdapter adapter = new FooAdapter();
Foo foo = new ByteBuddy()
.subclass(Foo.class)
.method(ElementMatchers.named("foo"))
.intercept(MethodDelegation.to(adapter))
.make()
.load(ClassLoader.getSystemClassLoader())
.getLoaded()
.newInstance();
foo.foo("hello", 10);
}
My Code is simple, I just want Delegate My Foo interface foo
method call to FooAdater
instance foo2
method. But when i run test, ByteBuddy seems do nothing.