Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何使用 Byte Buddy 添加具有给定值的注释?
我正在为 JUnit 生成测试类,我想用@RunWith(SomeRunner.class).
@RunWith(SomeRunner.class)
您可以在 fluent API 中注释类:
new ByteBuddy() .subclass(Object.class) .annotateType(AnnotationDescription.Builder.ofType(RunWith.class) .define("value", SomeRunner.class) .build()) .make();
或者,AnnotationDescription.Builder您也可以移交已加载的注释,构建器会自动将其转换为内部描述格式。
AnnotationDescription.Builder