Tue Apr 23, 2013 9:30 pm
public static Object constructObject(String className) {
Object[] params = { className };
Object result = null;
if (className != null)
className = className.trim();
try {
Class refClass = Class.forName(className);
result = refClass.newInstance();
} catch (ClassNotFoundException exception) {
// Do Something
} catch (IllegalAccessException exception) {
// Do Something
} catch (InstantiationException exception) {
// Do Something
}
return result;
}
Constructor argsConstructor = refClass
.getConstructor(argsClass);
// send the needed parameters for constructor if there are ?
result = argsConstructor.newInstance(constructorParams);
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.