List of utility methods to do Class New Instance
Object | newInstance(String className, Object arg1) new Instance Class[] argTypes = { arg1.getClass() };
Object[] args = { arg1 };
return newInstance(className, argTypes, args);
|
Object | newInstance(String className, Object... args) new Instance return newInstance(Class.forName(className), args);
|
Object | newInstance(String className, Object... args) new Instance Class<?> newoneClass = Class.forName(className);
return newInstance(newoneClass, args);
|
Object | newInstance(String className, Object... parameters) new Instance try { Class<?> objClass = Class.forName(className); Constructor<?> constructor = getConstructor(objClass, parameters); if (constructor != null) { return constructor.newInstance(parameters); } catch (Exception e) { return null; |
Object | newInstance(String className, Object... params) Creates a new instance. Constructor<?> best = null; int bestMatch = 0; for (Constructor<?> c : Class.forName(className).getConstructors()) { int p = match(c.getParameterTypes(), params); if (p > bestMatch) { bestMatch = p; best = c; if (best == null) { throw new NoSuchMethodException(className); return best.newInstance(params); |
Object | newInstance(String className, Object[] args) new Instance Class newoneClass = Class.forName(className); Class[] argsClass = new Class[args.length]; for (int i = 0, j = args.length; i < j; i++) { argsClass[i] = args[i].getClass(); Constructor cons = newoneClass.getConstructor(argsClass); return cons.newInstance(args); |
Object | newInstance(String className, Object[] args) new Instance Class newoneClass = Class.forName(className); Class[] argsClass = new Class[args.length]; for (int i = 0, j = args.length; i < j; i++) { argsClass[i] = args[i].getClass(); Constructor cons = newoneClass.getConstructor(argsClass); return cons.newInstance(args); |
Object | newInstance(String className, Object[] args) new Instance try { Class newoneClass = Class.forName(className); Class[] argsClass = new Class[args.length]; for (int i = 0, j = args.length; i < j; i++) { argsClass[i] = args[i].getClass(); Constructor cons = newoneClass.getConstructor(argsClass); return cons.newInstance(args); ... |
Object | newInstance(String classname, Properties properties) Get a new instance of an object based on its classpath. Object result = null; Class<?> theClass = null; try { theClass = Class.forName(classname); final Constructor constructor = theClass.getConstructor(Class.forName("java.util.Properties")); result = constructor.newInstance(properties); } catch (NoSuchMethodException e) { result = newInstance(theClass); ... |
Object | newInstance(String clazz) new Instance checkState(!Strings.isNullOrEmpty(clazz)); try { return Class.forName(clazz).newInstance(); } catch (Exception exception) { throw new RuntimeException(exception); |