/** * Create an object for the given class and initialize it from conf * @param theClass class of which an object is created * @param conf Configuration * @return a new object */ @SuppressWarnings("unchecked") public static <T> T newInstance(Class<T> theClass, Configuration conf) { T result; try { Constructor<?> ctor = CONSTRUCTOR_CACHE.getIfPresent(theClass); if (ctor == null) { ctor = theClass.getDeclaredConstructor(EMPTY_ARRAY); ctor.setAccessible(true); CONSTRUCTOR_CACHE.put(theClass, ctor); } result = (T)ctor.newInstance(); } catch (Exception e) { throw new RuntimeException(e); } setConf(result, conf); return result; }
/** * Create an object for the given class and initialize it from conf * @param theClass class of which an object is created * @param conf Configuration * @return a new object */ @SuppressWarnings("unchecked") public static <T> T newInstance(Class<T> theClass, Configuration conf) { T result; try { Constructor<?> ctor = CONSTRUCTOR_CACHE.getIfPresent(theClass); if (ctor == null) { ctor = theClass.getDeclaredConstructor(EMPTY_ARRAY); ctor.setAccessible(true); CONSTRUCTOR_CACHE.put(theClass, ctor); } result = (T)ctor.newInstance(); } catch (Exception e) { throw new RuntimeException(e); } setConf(result, conf); return result; }
/** * Create an object for the given class and initialize it from conf * @param theClass class of which an object is created * @param conf Configuration * @return a new object */ @SuppressWarnings("unchecked") public static <T> T newInstance(Class<T> theClass, Configuration conf) { T result; try { Constructor<?> ctor = CONSTRUCTOR_CACHE.getIfPresent(theClass); if (ctor == null) { ctor = theClass.getDeclaredConstructor(EMPTY_ARRAY); ctor.setAccessible(true); CONSTRUCTOR_CACHE.put(theClass, ctor); } result = (T)ctor.newInstance(); } catch (Exception e) { throw new RuntimeException(e); } setConf(result, conf); return result; }