@Test public void testNewInstance() throws Exception { assertTrue(ReflectionUtils.newInstance(String.class, null) instanceof String); }
@SuppressWarnings({"unchecked", "rawtypes"}) public static <T> T newInstance(final Class<T> theClass, Configuration conf) { T result; Constructor<T> retMethod = (Constructor<T>) CONSTRUCTOR_CACHE.get(theClass); if (retMethod == null) try { retMethod = AccessController.doPrivileged(new PrivilegedExceptionAction<Constructor<T>>() { public Constructor<T> run() throws NoSuchMethodException { Constructor<T> ret = theClass.getDeclaredConstructor(EMPTY_ARRAY); ret.setAccessible(true); return ret; } }); checkMemberAccess(theClass, retMethod); CONSTRUCTOR_CACHE.putIfAbsent(theClass, retMethod); } catch (PrivilegedActionException e) { throw new RuntimeException(e); } try { result = retMethod.newInstance(); } catch (Exception e) { throw new RuntimeException(e); } setConf(result, conf); return result; }
ReflectionUtils { @SuppressWarnings({"unchecked", "rawtypes"}) public static <T> T newInstance(final Class<T> theClass, Configuration conf) { T result; Constructor<T> retMethod = (Constructor<T>) CONSTRUCTOR_CACHE.get(theClass); if (retMethod == null) try { retMethod = AccessController.doPrivileged(new PrivilegedExceptionAction<Constructor<T>>() { public Constructor<T> run() throws NoSuchMethodException { Constructor<T> ret = theClass.getDeclaredConstructor(EMPTY_ARRAY); ret.setAccessible(true); return ret; } }); checkMemberAccess(theClass, retMethod); CONSTRUCTOR_CACHE.putIfAbsent(theClass, retMethod); } catch (PrivilegedActionException e) { throw new RuntimeException(e); } try { result = retMethod.newInstance(); } catch (Exception e) { throw new RuntimeException(e); } setConf(result, conf); return result; } }
ReflectionUtils { @SuppressWarnings({"unchecked", "rawtypes"}) public static <T> T newInstance(final Class<T> theClass, Configuration conf) { T result; Constructor<T> retMethod = (Constructor<T>) CONSTRUCTOR_CACHE.get(theClass); if (retMethod == null) try { retMethod = AccessController.doPrivileged(new PrivilegedExceptionAction<Constructor<T>>() { public Constructor<T> run() throws NoSuchMethodException { Constructor<T> ret = theClass.getDeclaredConstructor(EMPTY_ARRAY); ret.setAccessible(true); return ret; } }); checkMemberAccess(theClass, retMethod); CONSTRUCTOR_CACHE.putIfAbsent(theClass, retMethod); } catch (PrivilegedActionException e) { throw new RuntimeException(e); } try { result = retMethod.newInstance(); } catch (Exception e) { throw new RuntimeException(e); } setConf(result, conf); return result; }  }
ReflectionUtils { @SuppressWarnings({"unchecked", "rawtypes"}) public static <T> T newInstance(final Class<T> theClass, Configuration conf) { T result; Constructor<T> retMethod = (Constructor<T>) CONSTRUCTOR_CACHE.get(theClass); if (retMethod == null) try { retMethod = AccessController.doPrivileged(new PrivilegedExceptionAction<Constructor<T>>() { public Constructor<T> run() throws NoSuchMethodException { Constructor<T> ret = theClass.getDeclaredConstructor(EMPTY_ARRAY); ret.setAccessible(true); return ret; } }); checkMemberAccess(theClass, retMethod); CONSTRUCTOR_CACHE.putIfAbsent(theClass, retMethod); } catch (PrivilegedActionException e) { throw new RuntimeException(e); } try { result = retMethod.newInstance(); } catch (Exception e) { throw new RuntimeException(e); } setConf(result, conf); return result; }  static void setConf(Object theObject, Configuration conf); @SuppressWarnings({"unchecked", "rawtypes"}) static T newInstance(final Class<T> theClass, Configuration conf); @SuppressWarnings("unchecked") static T newInstanceFast(Class<T> theClass,
                                      Configuration configuration); @Deprecated static Method findUserClassMethod(final Class<?> inClass, final String methodName); static List<Method> findUserClassMethods(final Class<?> inClass, final String methodName); static Class<?> getClass(Type type); static void setField(Object target, String fieldname, Object value); static Field findDeclaredField(Class<?> inClass, String fieldname); static Method findDeclaredMethodRecursive(Class<?> inClass,
                                                   String methodName); static Method findDeclaredMethod(Class<?> inClass, String methodName); static List<Class<?>> getTypeArguments(Class<T> baseClass,
                                                    Class<? extends T> childClass); static void checkNonStaticField(Class<?> userImplClass,
                                         Class<?> parentClass); @Deprecated static void cloneWritableInto(Writable dst, Writable src); }
ReflectionUtils { @SuppressWarnings({"unchecked", "rawtypes"}) public static <T> T newInstance(final Class<T> theClass, Configuration conf) { T result; Constructor<T> retMethod = (Constructor<T>) CONSTRUCTOR_CACHE.get(theClass); if (retMethod == null) try { retMethod = AccessController.doPrivileged(new PrivilegedExceptionAction<Constructor<T>>() { public Constructor<T> run() throws NoSuchMethodException { Constructor<T> ret = theClass.getDeclaredConstructor(EMPTY_ARRAY); ret.setAccessible(true); return ret; } }); checkMemberAccess(theClass, retMethod); CONSTRUCTOR_CACHE.putIfAbsent(theClass, retMethod); } catch (PrivilegedActionException e) { throw new RuntimeException(e); } try { result = retMethod.newInstance(); } catch (Exception e) { throw new RuntimeException(e); } setConf(result, conf); return result; }  static void setConf(Object theObject, Configuration conf); @SuppressWarnings({"unchecked", "rawtypes"}) static T newInstance(final Class<T> theClass, Configuration conf); @SuppressWarnings("unchecked") static T newInstanceFast(Class<T> theClass,
                                      Configuration configuration); @Deprecated static Method findUserClassMethod(final Class<?> inClass, final String methodName); static List<Method> findUserClassMethods(final Class<?> inClass, final String methodName); static Class<?> getClass(Type type); static void setField(Object target, String fieldname, Object value); static Field findDeclaredField(Class<?> inClass, String fieldname); static Method findDeclaredMethodRecursive(Class<?> inClass,
                                                   String methodName); static Method findDeclaredMethod(Class<?> inClass, String methodName); static List<Class<?>> getTypeArguments(Class<T> baseClass,
                                                    Class<? extends T> childClass); static void checkNonStaticField(Class<?> userImplClass,
                                         Class<?> parentClass); @Deprecated static void cloneWritableInto(Writable dst, Writable src);  }