MCPcopy Create free account
hub / github.com/alibaba/DataX / ClassUtil

Class ClassUtil

core/src/main/java/com/alibaba/datax/core/util/ClassUtil.java:5–40  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3import java.lang.reflect.Constructor;
4
5public final class ClassUtil {
6
7 /**
8 * 通过反射构造类对象
9 *
10 * @param className
11 * 反射的类名称
12 * @param t
13 * 反射类的类型Class对象
14 * @param args
15 * 构造参数
16 *
17 * */
18 @SuppressWarnings({ "rawtypes", "unchecked" })
19 public static <T> T instantiate(String className, Class<T> t,
20 Object... args) {
21 try {
22 Constructor constructor = (Constructor) Class.forName(className)
23 .getConstructor(ClassUtil.toClassType(args));
24 return (T) constructor.newInstance(args);
25 } catch (Exception e) {
26 throw new IllegalArgumentException(e);
27 }
28 }
29
30 private static Class<?>[] toClassType(Object[] args) {
31 Class<?>[] clazzs = new Class<?>[args.length];
32
33 for (int i = 0, length = args.length; i < length; i++) {
34 clazzs[i] = args[i].getClass();
35 }
36
37 return clazzs;
38 }
39
40}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected