Samples: Why some methods are not exists?
I've tried to use byte-buddy with their examples. But why some methods are not available?
import net.bytebuddy.*;
import net.bytebuddy.dynamic.*;
import net.bytebuddy.dynamic.loading.*;
import net.bytebuddy.implementation.*;
import net.bytebuddy.pool.*;
class Foo {
public String bar() { return null; }
public String foo() { return null; }
public String foo(Object o) { return null; }
}
public class Test {
public Test() {
try {
Foo dynamicFoo = new ByteBuddy()
.subclass(Foo.class)
.method(isDeclaredBy(Foo.class)).intercept(FixedValue.value("One!"))
.method(named("foo")).intercept(FixedValue.value("Two!"))
.method(named("foo").and(takesArguments(1))).intercept(FixedValue.value("Three!"))
.make()
.load(getClass().getClassLoader())
.getLoaded()
.newInstance();
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
new Test();
}
}
What do you mean by that? There are no methods invoked in your sample, you only construct the instance.
Please use the simple samples on the website.
Create a new project in eclipse, add byte-buddy & ASM libs and create the class above in the question.
You will see that some methods like isDeclaredBy or names not exists.
They are static imports by ElementMatchers.
Please explain yor answer.
On the site only following informations are available:
Byte Buddy is a light-weight library and only depends on the visitor API of the Java byte code parser library ASM which does itself not require any further dependencies.
For that, i have cloned the byte-buddy repo, build it with nvm package and packed the builded .jar and the .jar from ASM in my project folder.
I had tried it with IntelliJ (Gradle), here the same Problem:
In Java, you need to inport symbols. Normally, your IDE gives you suggestions in the context menu.