java - 如何在 ByteBuddy 转换期间增加方法?
问题描述
解决方案
Can you share a reconstruction of your example? In a simple example, I observe the expected behavior:
public class Bar {
public static void main(String[] args) throws Exception {
Class<?> type = new ByteBuddy().subclass(Object.class)
.visit(Advice.to(Bar.class).on(named("m")))
.defineMethod("m", void.class, Visibility.PUBLIC)
.intercept(MethodDelegation.to(Bar.class))
.make()
.load(Bar.class.getClassLoader(), ClassLoadingStrategy.Default.WRAPPER)
.getLoaded();
type.getMethod("m").invoke(type.getConstructor().newInstance());
}
@BindingPriority(2)
public static void delegation() {
System.out.println("Delegation!");
}
@Advice.OnMethodEnter
public static void enter() {
System.out.println("Advice!");
}
}
This example prints both Advice! and Delegation!.
推荐阅读
- javascript - 单击主选择框时如何自动打开第二个选择框?
- python - Python:我如何计算一个单词在文本文件中出现的次数
- mongodb - 如何设置我的 VPS Webmin/Virtualmin 服务器以在托管网站中显示来自 MongoDB 的数据?
- python - 如何提高对表面缺陷的检测?
- c# - 如何在 WPF 中设置不可点击的元素
- android - 更改背景图像但保持可绘制到视图 android xml
- python - 消除不满足两个条件的数组行
- javascript - Javascript 在页面上显示/隐藏多个实例 - 无法更改 ID
- html - 如何使我的网站的特定部分看起来像这样?(使用 HTML 和 CSS。)
- laravel - 无法为角色创建搜索过滤器,该过滤器显示具有所选角色的所有用户 - Laravel