import net.bytebuddy.ByteBuddy; import net.bytebuddy.implementation.FixedValue; import net.bytebuddy.matcher.ElementMatchers; public class HelloWorldAgent { public static void main(String[] args) throws Exception { Class<?> dynamicType = new ByteBuddy() .subclass(Object.class) .method(ElementMatchers.named("toString")) .intercept(FixedValue.value("Hello World!")) .make() .load(HelloWorldAgent.class.getClassLoader()) .getLoaded(); System.out.println(dynamicType.newInstance().toString()); } }


上一篇:
下一篇:
切换中文