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