All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.nutz.lang.born.MethodCastingBorning Maven / Gradle / Ivy

Go to download

Nutz, which is a collections of lightweight frameworks, each of them can be used independently

There is a newer version: 1.r.72
Show newest version
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);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy