I have an interface Action:
package action;
public interface Action {
public String act();
}
Class SimpleAction:
package action;
public class SimpleAction implements Action {
String action;
public SimpleAction() {}
public SimpleAction(String x) {
this.action = x;
}
@Override
public String act() {
return "Act method from -" + this.action;
}
}
Class ComplexAction:
package action;
public class ComplexAction implements Action{
String action;
public ComplexAction() {}
public ComplexAction(String x) {
this.action = x;
}
@Override
public String act() {
return "Act method from -" + this.action;
}
}
I want to create a function which takes the name of class and returns an object of that class. This is what I have so far in my function -
public static Action resultOfActMethod(String objclass){
Class clazz = Class.forName(objclass);
MethodHandles.Lookup lookup = MethodHandles.lookup();
MethodHandle mh = lookup.findConstructor(clazz,MethodType.methodType(void.class, String.class));
}