Is it possible to use Byte Buddy to redefine a private method of a class? It seems that the entry point into using Byte Buddy is always sub-classing an existing class. When doing this, it is obviously not possible to redefine a private method of the parent class (at least not in a way that the redefined method is used in the parent class).
Consider the following example:
public class Foo {
public void sayHello() {
System.out.println(getHello());
}
private String getHello() {
return "Hello World!";
}
}
Foo foo = new ByteBuddy()
.subclass(Foo.class)
.method(named("getHello")).intercept(FixedValue.value("Byte Buddy!"))
.make()
.load(Main.class.getClassLoader(), ClassLoadingStrategy.Default.WRAPPER)
.getLoaded()
.newInstance();
foo.sayHello();
The output will be "Hello World!". Is there any chance to get "Byte Buddy!" as output?