How can I use Byte Buddy to add an annotation with a given value?
I'm playing around with generating test classes for JUnit and I'd like to annotate a generated class by @RunWith(SomeRunner.class). 
You can annotate a class within the fluent API:
new ByteBuddy()
  .subclass(Object.class)
  .annotateType(AnnotationDescription.Builder.ofType(RunWith.class)
                                             .define("value", SomeRunner.class)
                                             .build())
  .make();
Alternatively to the AnnotationDescription.Builder you can also hand over a loaded annotation, the builder automatically converts it to the internal description format.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With