参考网址https://notes.diguage.com/byte-buddy-tutorial/
1、Maven依赖:
net.bytebuddy
byte-buddy
1.7.9
net.bytebuddy
byte-buddy-agent
1.7.9
2、Byte Buddy 的默认配置提供了 NamingStrategy,它基于动态类型的超类名称来随机生成类名。
public static void main(String[] args) {
DynamicType.Unloaded<?> dynamicType = new ByteBuddy()
.with(new NamingStrategy.AbstractBase() {
@Override
protected String name(TypeDescription typeDescription) {
return "i.love.ByteBuddy." + typeDescription.getSimpleName();
}
})
.subclass(Object.class)
.make();
DynamicType.Unloaded<?> dynamicType1 = new ByteBuddy()
.with(new NamingStrategy.AbstractBase() {
@Override
protected String name(TypeDescription typeDescription) {
return "i.love.ByteBuddy." + typeDescription.getSimpleName();
}
})