I try to redefine simple non-static method but I get an exception:
Exception in thread "main" java.lang.UnsupportedOperationException: class redefinition failed: attempted to change the schema (add/remove fields)
Classes:
class Source {
def hello(name: String): String = ""
}
class Target {
def hello(name: String): String = "Hello" + name + "!"
}
Call:
new ByteBuddy()
.rebase(classOf[Source])
.method(ElementMatchers.named("hello"))
.intercept(MethodDelegation.to(new Target))
.make()
.load(classOf[Source].getClassLoader, ClassReloadingStrategy.fromInstalledAgent())
.getLoaded
.newInstance()
.hello("World")
Classes above are scala classes but they compile to standard java classes.
How to redefine method correctly?