Search code examples
javabyte-buddy

Can I redefine which super class to extend in ByteBuddy?


As the title reads, can I redefine the extends clause when redefining a class using ByteBuddy?

That is, redefining class A from A extends B to A extends C for example.

I've read the javadoc and it only suggests a DynamicType.Builder.implement mechanism which only accepts additional interfaces, but it's not for superclasses.

Is there someone tried this?

thanks.


Solution

  • That's a rather difficult translation as this affects a significant portion of the class when it comes to super class access and super method calls.

    You can register a ClassVisitorWrapper and change the property using ASM on the ClassVisitor's visit method.