Please complete the method dynamicClassToString() to override toString() method from Object.class. Make this method return "Hello, ByteBuddy!".
import net.bytebuddy.ByteBuddy;
import net.bytebuddy.dynamic.loading.ClassLoadingStrategy;
import net.bytebuddy.implementation.FixedValue;
import static net.bytebuddy.matcher.ElementMatchers.named;
public class DynamicClass {
public String dynamicClassToString() throws Exception {
Class<?> dynamicClass = new ByteBuddy()
.subclass(Object.class)
//select the appropriate lines
.make()
.load(DynamicClass.class.getClassLoader(), ClassLoadingStrategy.Default.WRAPPER)
.getLoaded();
Object instance = dynamicClass.getDeclaredConstructor().newInstance();
return instance.toString();
}
}