Where does bytecode injection happen?
Motivation I have a SomeObject.java file: class SomeObject { String name; } Compiling it creates a bytecode-containing SomeObject.class file. 0xCAFEBABE... If we use SomeObject on the JVM, it is loaded by the current classloader and all works fine. Now let's assume that I'd like to have some dynamic code generation. I can write my custom annotation @Target(ElementType.TYPE) public @interface Data { ... } and add it as a modifier to the class declaration: @Data class SomeObject { String name; } I can also retain it for the runtime with @Retention(RetentionPolicy.RUNTIME) : @Retention