Skip to content

Instantly share code, notes, and snippets.

@dogmatic69
Created July 24, 2017 20:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dogmatic69/09671ae2a86d1abee81780ba3e6a8d92 to your computer and use it in GitHub Desktop.
Save dogmatic69/09671ae2a86d1abee81780ba3e6a8d92 to your computer and use it in GitHub Desktop.
private Object loadClass(String className, Object arg) {
Class classToLoad = null;
try {
classToLoad = Class.forName(className);
} catch (ClassNotFoundException e) {
Debugger.out(e);
return null;
}
Class[] types = {Double.TYPE, this.getClass()};
Constructor constructor = null;
try {
constructor = classToLoad.getConstructor(types);
} catch (NoSuchMethodException e) {
Debugger.out(e);
return null;
}
Object[] parameters = {arg, this};
Object classInstance = null;
try {
classInstance = constructor.newInstance(arg);
} catch (InvocationTargetException e) {
Debugger.out(e);
return null;
} catch (IllegalAccessException e) {
Debugger.out(e);
return null;
} catch (InstantiationException e) {
Debugger.out(e);
return null;
}
return classInstance;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment