Complete method getField()

Report a typo

Please complete method getField(). Dynamically create a class using ByteBuddy and retrieve the value of a specific field within an instance of that class. Select all lines that need to add.

import net.bytebuddy.ByteBuddy;
import net.bytebuddy.dynamic.loading.ClassLoadingStrategy;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;

public class VariableDynamicClass {
    public String getField() throws Exception {
        Class<?> type = new ByteBuddy()
                .subclass(Object.class)

                // select the appropriate lines

                .make()
                .load(VariableDynamicClass.class.getClassLoader(), ClassLoadingStrategy.Default.WRAPPER)
                .getLoaded();

        Object instance = type.getDeclaredConstructor().newInstance();

        Field fieldX = type.getDeclaredField("Field");
        fieldX.set(instance, "NameOfField");
        return fieldX.get(instance).toString();
    }
}
Select one or more options from the list
___

Create a free account to access the full topic