My project contains this package : com.X.Y.Z.controller
This package includes 3 files
ControllerA.java
public class ControllerA {
public static void insert(Context context, ModelA model) {/*do somethings*/}
}
ControllerB.java
public class ControllerB {
public static void insert(Context context, ModelB model) {/*do somethings*/}
}
MainController.java
I use following code to invoke insert method from Controller A or B it depends on some condition
public static void insert(Context context, Object object) {
Class<?> clazz = Class.forName(mClass); //Controller A or B
Method method = clazz.getMethod("insert", ?);
method.invoke(null, ?);
}
how do i pass arguments ? object may be ModelA or ModelB
I apologize if my wording is not true
clazz.getMethod("insert", Context.class, CCC)whereCCCis eitherModelA.classorModelB.class. But I don't see where you have a way to get theModelclass. Will this be passed as a parameter toinsert, or will there be some other way to obtain it, or do you want to search the class for methods namedinsertand figure out theModelclass by looking at the method parameters?ModelAorModelBWill this be passed as a parameter toinsert