Search code examples
byte-buddy

ByteBuddy how to have some code executed at class load time


I am using bytebuddy to dynamically create Classes, Enums and Interfaces and I want to have some code executed at class load time to initialize some of the static fields which is normaly done in <clinit>. what are the APIs in bytebuddy that I can use to do this ?


Solution

  • You can instrument the initializer via:

    builder.invokeable(isTypeInitalizer()).intercept(...)