List of utility methods to do Class New Instance
T | newInstance(Class Creates a new instance of the class. Constructor constructor; try { constructor = cls.getConstructor(); } catch (NoSuchMethodException e) { e.printStackTrace(); return null; if (!constructor.isAccessible()) ... |
T | newInstance(Class new Instance Constructor<T> constr = cls.getConstructor((Class[]) null); if (!constr.isAccessible()) { constr.setAccessible(true); T result = constr.newInstance((Object[]) null); return result; |
T | newInstance(Class Creates a new instance matching possible constructors with provided args. Constructor<T> declaredConstructor = args.length == 0 ? getConstructor(cls) : getConstructor(cls, args); boolean accessible = declaredConstructor.isAccessible(); if (accessible) { return declaredConstructor.newInstance(args); } else { declaredConstructor.setAccessible(true); try { return declaredConstructor.newInstance(args); ... |
T | newInstance(Class new Instance try { Constructor<T> cnstr = clz.getDeclaredConstructor(argType); cnstr.setAccessible(true); return cnstr.newInstance(arg); } catch (Exception e) { throw new RuntimeException(e); |
T[] | newInstance(Class new Instance return (T[]) Array.newInstance(componentType, size);
|
T[] | newInstance(Class Constructs a new array of the given non-primitive component type and length. if (elementType.isPrimitive()) { throw new IllegalArgumentException("element type cannot be primitive: " + elementType); @SuppressWarnings("unchecked") T ret[] = (T[]) Array.newInstance(elementType, len); return ret; |
T | newInstance(Class new Instance T t = null; try { Constructor<T> constructor = klass.getDeclaredConstructor(); if (constructor != null) { constructor.setAccessible(true); t = constructor.newInstance(); } catch (Exception e) { ... |
T | newInstance(Class new Instance T result; try { Constructor<T> meth = (Constructor<T>) CONSTRUCTOR_CACHE.get(klass); if (meth == null) { meth = klass.getDeclaredConstructor(new Class[] {}); meth.setAccessible(true); CONSTRUCTOR_CACHE.put(klass, meth); result = meth.newInstance(); } catch (Exception e) { throw new RuntimeException(e); return result; |
T | newInstance(Class Creates a new instance of klass . throw new RuntimeException("ReflectionHelper can't be used from web mode."); |
T | newInstance(Class new Instance try { return (T) klass.newInstance(); } catch (Exception e) { throw new IllegalArgumentException("instance class[" + klass.getName() + "] with ex:", e); |