org.nutz.lang.born.MethodCastingBorning Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of nutz Show documentation
Show all versions of nutz Show documentation
Nutz, which is a collections of lightweight frameworks, each of them can be used independently
package org.nutz.lang.born;
import java.lang.reflect.Method;
import org.nutz.lang.Lang;
public class MethodCastingBorning implements Borning {
private Method method;
private Class>[] pts;
public MethodCastingBorning(Method method) {
this.method = method;
this.method.setAccessible(true);
this.pts = method.getParameterTypes();
}
@SuppressWarnings("unchecked")
public T born(Object... args) {
try {
args = Lang.array2ObjectArray(args, pts);
return (T) method.invoke(null, args);
}
catch (Exception e) {
throw new BorningException(e, method.getDeclaringClass(), args);
}
}
}