List of utility methods to do Class New Instance
T | newInstance(Class Create an object for the given class and initialize it from conf T result; try { Constructor<T> meth = (Constructor<T>) CONSTRUCTOR_CACHE.get(theClass); if (meth == null) { meth = theClass.getDeclaredConstructor(EMPTY_CLASS_ARRAY); meth.setAccessible(true); CONSTRUCTOR_CACHE.put(theClass, meth); result = meth.newInstance(initArgs); } catch (Exception e) { throw new RuntimeException(e); return result; |
T | newInstance(Class Creates a new zero-arg instance of the specified class try { Constructor<T> ctr = (Constructor<T>) CONSTRUCTOR_CACHE.get(className); if (ctr == null) { Class<T> clazz = (Class<T>) Class.forName(className); ctr = (Constructor<T>) clazz.getDeclaredConstructor(EMPTY_ARRAY); ctr.setAccessible(true); CONSTRUCTOR_CACHE.put(className, ctr); return ctr.newInstance(); } catch (Exception e) { throw new RuntimeException("Failed to instantiate task: " + className, e); |
T | newInstance(Class Create an object for the given class. T result; try { Constructor<T> meth = (Constructor<T>) constructorCache.get(theCls); if (null == meth) { meth = theCls.getDeclaredConstructor(); meth.setAccessible(true); constructorCache.put(theCls, meth); result = meth.newInstance(); } catch (Exception e) { throw new RuntimeException(e); return result; |
T | newInstance(Class new Instance Constructor<T> constructor; try { constructor = type.getDeclaredConstructor(); constructor.setAccessible(true); } catch (NoSuchMethodException e) { throw new IllegalArgumentException( "Couldn't create Page Object. Missing 0 arg constructor on type " + type, e); T instance; try { instance = constructor.newInstance(); } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) { throw new IllegalArgumentException("Unable to create instance of type " + type, e); return instance; |
T | newInstance(Class Creates new instance from the given type. try { return type.newInstance(); } catch (InstantiationException e) { throw new RuntimeException(e); } catch (IllegalAccessException e) { throw new RuntimeException(e); |
T | newInstance(Class new Instance try { Constructor<T> constructor = type.getDeclaredConstructor(); if (type.getEnclosingClass() != null && constructor == null) { throw new IllegalArgumentException("Inner class is not supported"); } else { if (!constructor.isAccessible()) { constructor.setAccessible(true); return constructor.newInstance(); } catch (ReflectiveOperationException e) { throw new RuntimeException(e); |
T | newInstance(Class A helper method to create a new instance of a type using the default constructor arguments. try { return type.newInstance(); } catch (InstantiationException e) { throw new RuntimeException(e); } catch (IllegalAccessException e) { throw new RuntimeException(e); |
T | newInstance(Class new Instance try { Constructor<T> customConstructor = getMungedConstructor(type); return customConstructor.newInstance(new Object[0]); } catch (Exception e) { throw new RuntimeException("Cannot construct " + type.getName(), e); |
T | newInstance(Class new Instance return newInstance(type, new Class<?>[0]); |
T | newInstance(Class Creates a new instance of the given type by invoking the default constructor. try { Constructor<T> constructor = (Constructor<T>) CACHED_DEFAULT_CONSTRUCTORS.get(type); if (constructor == null) { CACHED_DEFAULT_CONSTRUCTORS.put(type, constructor = type.getDeclaredConstructor()); constructor.setAccessible(true); return constructor.newInstance(); } catch (Exception e) { ... |