当前位置: 首页>>代码示例>>Java>>正文


Java ClassUtils.toClass方法代码示例

本文整理汇总了Java中org.apache.commons.lang3.ClassUtils.toClass方法的典型用法代码示例。如果您正苦于以下问题:Java ClassUtils.toClass方法的具体用法?Java ClassUtils.toClass怎么用?Java ClassUtils.toClass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.lang3.ClassUtils的用法示例。


在下文中一共展示了ClassUtils.toClass方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: invokeMethod

import org.apache.commons.lang3.ClassUtils; //导入方法依赖的package包/类
/**
 * 直接调用对象方法, 无视private/protected修饰符.
 * 
 * 根据传入参数的实际类型进行匹配
 */
public static <T> T invokeMethod(Object obj, String methodName, Object... args) {
	Object[] theArgs = ArrayUtils.nullToEmpty(args);
	final Class<?>[] parameterTypes = ClassUtils.toClass(theArgs);
	return (T) invokeMethod(obj, methodName, theArgs, parameterTypes);
}
 
开发者ID:zhangjunfang,项目名称:util,代码行数:11,代码来源:ReflectionUtil.java

示例2: invokeConstructor

import org.apache.commons.lang3.ClassUtils; //导入方法依赖的package包/类
/**
 * <p>Returns a new instance of the specified class inferring the right constructor
 * from the types of the arguments.</p>
 * <p>
 * <p>This locates and calls a constructor.
 * The constructor signature must match the argument types by assignment compatibility.</p>
 *
 * @param <T>  the type to be constructed
 * @param cls  the class to be constructed, not {@code null}
 * @param args the array of arguments, {@code null} treated as empty
 * @return new instance of {@code cls}, not {@code null}
 * @throws NullPointerException      if {@code cls} is {@code null}
 * @throws NoSuchMethodException     if a matching constructor cannot be found
 * @throws IllegalAccessException    if invocation is not permitted by security
 * @throws InvocationTargetException if an error occurs on invocation
 * @throws InstantiationException    if an error occurs on instantiation
 * @see #invokeConstructor(java.lang.Class, java.lang.Object[], java.lang.Class[])
 */
public static <T> T invokeConstructor(final Class<T> cls, Object... args)
        throws NoSuchMethodException, IllegalAccessException, InvocationTargetException,
        InstantiationException {
    args = ArrayUtils.nullToEmpty(args);
    final Class<?> parameterTypes[] = ClassUtils.toClass(args);
    return invokeConstructor(cls, args, parameterTypes);
}
 
开发者ID:rogerxaic,项目名称:gestock,代码行数:26,代码来源:ConstructorUtils.java

示例3: invokeExactConstructor

import org.apache.commons.lang3.ClassUtils; //导入方法依赖的package包/类
/**
 * <p>Returns a new instance of the specified class inferring the right constructor
 * from the types of the arguments.</p>
 * <p>
 * <p>This locates and calls a constructor.
 * The constructor signature must match the argument types exactly.</p>
 *
 * @param <T>  the type to be constructed
 * @param cls  the class to be constructed, not {@code null}
 * @param args the array of arguments, {@code null} treated as empty
 * @return new instance of {@code cls}, not {@code null}
 * @throws NullPointerException      if {@code cls} is {@code null}
 * @throws NoSuchMethodException     if a matching constructor cannot be found
 * @throws IllegalAccessException    if invocation is not permitted by security
 * @throws InvocationTargetException if an error occurs on invocation
 * @throws InstantiationException    if an error occurs on instantiation
 * @see #invokeExactConstructor(java.lang.Class, java.lang.Object[], java.lang.Class[])
 */
public static <T> T invokeExactConstructor(final Class<T> cls, Object... args)
        throws NoSuchMethodException, IllegalAccessException, InvocationTargetException,
        InstantiationException {
    args = ArrayUtils.nullToEmpty(args);
    final Class<?> parameterTypes[] = ClassUtils.toClass(args);
    return invokeExactConstructor(cls, args, parameterTypes);
}
 
开发者ID:rogerxaic,项目名称:gestock,代码行数:26,代码来源:ConstructorUtils.java

示例4: invokeMethod

import org.apache.commons.lang3.ClassUtils; //导入方法依赖的package包/类
/**
 * <p>Invokes a named method whose parameter type matches the object type.</p>
 * <p>
 * <p>This method delegates the method search to {@link #getMatchingAccessibleMethod(Class, String, Class[])}.</p>
 * <p>
 * <p>This method supports calls to methods taking primitive parameters
 * via passing in wrapping classes. So, for example, a {@code Boolean} object
 * would match a {@code boolean} primitive.</p>
 * <p>
 * <p>This is a convenient wrapper for
 * {@link #invokeMethod(Object object, String methodName, Object[] args, Class[] parameterTypes)}.
 * </p>
 *
 * @param object     invoke method on this object
 * @param methodName get method with this name
 * @param args       use these arguments - treat null as empty array
 * @return The value returned by the invoked method
 * @throws NoSuchMethodException     if there is no such accessible method
 * @throws InvocationTargetException wraps an exception thrown by the method invoked
 * @throws IllegalAccessException    if the requested method is not accessible via reflection
 */
public static Object invokeMethod(final Object object, final String methodName,
                                  Object... args) throws NoSuchMethodException,
        IllegalAccessException, InvocationTargetException {
    args = ArrayUtils.nullToEmpty(args);
    final Class<?>[] parameterTypes = ClassUtils.toClass(args);
    return invokeMethod(object, methodName, args, parameterTypes);
}
 
开发者ID:rogerxaic,项目名称:gestock,代码行数:29,代码来源:MethodUtils.java

示例5: invokeExactMethod

import org.apache.commons.lang3.ClassUtils; //导入方法依赖的package包/类
/**
 * <p>Invokes a method with no parameters.</p>
 * <p>
 * <p>This uses reflection to invoke the method obtained from a call to
 * {@link #getAccessibleMethod}(Class,String,Class[])}.</p>
 *
 * @param object     invoke method on this object
 * @param methodName get method with this name
 * @param args       use these arguments - treat null as empty array
 * @return The value returned by the invoked method
 * @throws NoSuchMethodException     if there is no such accessible method
 * @throws InvocationTargetException wraps an exception thrown by the
 *                                   method invoked
 * @throws IllegalAccessException    if the requested method is not accessible
 *                                   via reflection
 */
public static Object invokeExactMethod(final Object object, final String methodName,
                                       Object... args) throws NoSuchMethodException,
        IllegalAccessException, InvocationTargetException {
    args = ArrayUtils.nullToEmpty(args);
    final Class<?>[] parameterTypes = ClassUtils.toClass(args);
    return invokeExactMethod(object, methodName, args, parameterTypes);
}
 
开发者ID:rogerxaic,项目名称:gestock,代码行数:24,代码来源:MethodUtils.java

示例6: invokeStaticMethod

import org.apache.commons.lang3.ClassUtils; //导入方法依赖的package包/类
/**
 * <p>Invokes a named {@code static} method whose parameter type matches the object type.</p>
 * <p>
 * <p>This method delegates the method search to {@link #getMatchingAccessibleMethod(Class, String, Class[])}.</p>
 * <p>
 * <p>This method supports calls to methods taking primitive parameters
 * via passing in wrapping classes. So, for example, a {@code Boolean} class
 * would match a {@code boolean} primitive.</p>
 * <p>
 * <p>This is a convenient wrapper for
 * {@link #invokeStaticMethod(Class, String, Object[], Class[])}.
 * </p>
 *
 * @param cls        invoke static method on this class
 * @param methodName get method with this name
 * @param args       use these arguments - treat {@code null} as empty array
 * @return The value returned by the invoked method
 * @throws NoSuchMethodException     if there is no such accessible method
 * @throws InvocationTargetException wraps an exception thrown by the
 *                                   method invoked
 * @throws IllegalAccessException    if the requested method is not accessible
 *                                   via reflection
 */
public static Object invokeStaticMethod(final Class<?> cls, final String methodName,
                                        Object... args) throws NoSuchMethodException,
        IllegalAccessException, InvocationTargetException {
    args = ArrayUtils.nullToEmpty(args);
    final Class<?>[] parameterTypes = ClassUtils.toClass(args);
    return invokeStaticMethod(cls, methodName, args, parameterTypes);
}
 
开发者ID:rogerxaic,项目名称:gestock,代码行数:31,代码来源:MethodUtils.java

示例7: invokeExactStaticMethod

import org.apache.commons.lang3.ClassUtils; //导入方法依赖的package包/类
/**
 * <p>Invokes a {@code static} method whose parameter types match exactly the object
 * types.</p>
 * <p>
 * <p>This uses reflection to invoke the method obtained from a call to
 * {@link #getAccessibleMethod(Class, String, Class[])}.</p>
 *
 * @param cls        invoke static method on this class
 * @param methodName get method with this name
 * @param args       use these arguments - treat {@code null} as empty array
 * @return The value returned by the invoked method
 * @throws NoSuchMethodException     if there is no such accessible method
 * @throws InvocationTargetException wraps an exception thrown by the
 *                                   method invoked
 * @throws IllegalAccessException    if the requested method is not accessible
 *                                   via reflection
 */
public static Object invokeExactStaticMethod(final Class<?> cls, final String methodName,
                                             Object... args) throws NoSuchMethodException,
        IllegalAccessException, InvocationTargetException {
    args = ArrayUtils.nullToEmpty(args);
    final Class<?>[] parameterTypes = ClassUtils.toClass(args);
    return invokeExactStaticMethod(cls, methodName, args, parameterTypes);
}
 
开发者ID:rogerxaic,项目名称:gestock,代码行数:25,代码来源:MethodUtils.java

示例8: invokeConstructor

import org.apache.commons.lang3.ClassUtils; //导入方法依赖的package包/类
/**
 * <p>Returns a new instance of the specified class inferring the right constructor
 * from the types of the arguments.</p>
 * 
 * <p>This locates and calls a constructor.
 * The constructor signature must match the argument types by assignment compatibility.</p>
 *
 * @param <T> the type to be constructed
 * @param cls  the class to be constructed, not {@code null}
 * @param args  the array of arguments, {@code null} treated as empty
 * @return new instance of {@code cls}, not {@code null}
 *
 * @throws NullPointerException if {@code cls} is {@code null}
 * @throws NoSuchMethodException if a matching constructor cannot be found
 * @throws IllegalAccessException if invocation is not permitted by security
 * @throws InvocationTargetException if an error occurs on invocation
 * @throws InstantiationException if an error occurs on instantiation
 * @see #invokeConstructor(java.lang.Class, java.lang.Object[], java.lang.Class[])
 */
public static <T> T invokeConstructor(final Class<T> cls, Object... args)
        throws NoSuchMethodException, IllegalAccessException, InvocationTargetException,
        InstantiationException {
    args = ArrayUtils.nullToEmpty(args);
    final Class<?> parameterTypes[] = ClassUtils.toClass(args);
    return invokeConstructor(cls, args, parameterTypes);
}
 
开发者ID:Sukelluskello,项目名称:VectorAttackScanner,代码行数:27,代码来源:ConstructorUtils.java

示例9: invokeExactConstructor

import org.apache.commons.lang3.ClassUtils; //导入方法依赖的package包/类
/**
 * <p>Returns a new instance of the specified class inferring the right constructor
 * from the types of the arguments.</p>
 *
 * <p>This locates and calls a constructor.
 * The constructor signature must match the argument types exactly.</p>
 *
 * @param <T> the type to be constructed
 * @param cls the class to be constructed, not {@code null}
 * @param args the array of arguments, {@code null} treated as empty
 * @return new instance of {@code cls}, not {@code null}
 *
 * @throws NullPointerException if {@code cls} is {@code null}
 * @throws NoSuchMethodException if a matching constructor cannot be found
 * @throws IllegalAccessException if invocation is not permitted by security
 * @throws InvocationTargetException if an error occurs on invocation
 * @throws InstantiationException if an error occurs on instantiation
 * @see #invokeExactConstructor(java.lang.Class, java.lang.Object[], java.lang.Class[])
 */
public static <T> T invokeExactConstructor(final Class<T> cls, Object... args)
        throws NoSuchMethodException, IllegalAccessException, InvocationTargetException,
        InstantiationException {
    args = ArrayUtils.nullToEmpty(args);
    final Class<?> parameterTypes[] = ClassUtils.toClass(args);
    return invokeExactConstructor(cls, args, parameterTypes);
}
 
开发者ID:Sukelluskello,项目名称:VectorAttackScanner,代码行数:27,代码来源:ConstructorUtils.java

示例10: invokeMethod

import org.apache.commons.lang3.ClassUtils; //导入方法依赖的package包/类
/**
 * <p>Invokes a named method whose parameter type matches the object type.</p>
 *
 * <p>This method delegates the method search to {@link #getMatchingAccessibleMethod(Class, String, Class[])}.</p>
 *
 * <p>This method supports calls to methods taking primitive parameters 
 * via passing in wrapping classes. So, for example, a {@code Boolean} object
 * would match a {@code boolean} primitive.</p>
 *
 * <p>This is a convenient wrapper for
 * {@link #invokeMethod(Object object,String methodName, Object[] args, Class[] parameterTypes)}.
 * </p>
 *
 * @param object invoke method on this object
 * @param methodName get method with this name
 * @param args use these arguments - treat null as empty array
 * @return The value returned by the invoked method
 *
 * @throws NoSuchMethodException if there is no such accessible method
 * @throws InvocationTargetException wraps an exception thrown by the method invoked
 * @throws IllegalAccessException if the requested method is not accessible via reflection
 */
public static Object invokeMethod(final Object object, final String methodName,
        Object... args) throws NoSuchMethodException,
        IllegalAccessException, InvocationTargetException {
    args = ArrayUtils.nullToEmpty(args);
    final Class<?>[] parameterTypes = ClassUtils.toClass(args);
    return invokeMethod(object, methodName, args, parameterTypes);
}
 
开发者ID:Sukelluskello,项目名称:VectorAttackScanner,代码行数:30,代码来源:MethodUtils.java

示例11: invokeExactMethod

import org.apache.commons.lang3.ClassUtils; //导入方法依赖的package包/类
/**
 * <p>Invokes a method whose parameter types match exactly the object
 * types.</p>
 *
 * <p>This uses reflection to invoke the method obtained from a call to
 * {@link #getAccessibleMethod}(Class,String,Class[])}.</p>
 *
 * @param object invoke method on this object
 * @param methodName get method with this name
 * @param args use these arguments - treat {@code null} as empty array
 * @return The value returned by the invoked method
 *
 * @throws NoSuchMethodException if there is no such accessible method
 * @throws InvocationTargetException wraps an exception thrown by the
 *  method invoked
 * @throws IllegalAccessException if the requested method is not accessible
 *  via reflection
 */
public static Object invokeExactMethod(final Object object, final String methodName,
        Object... args) throws NoSuchMethodException,
        IllegalAccessException, InvocationTargetException {
    args = ArrayUtils.nullToEmpty(args);
    final Class<?>[] parameterTypes = ClassUtils.toClass(args);
    return invokeExactMethod(object, methodName, args, parameterTypes);
}
 
开发者ID:Sukelluskello,项目名称:VectorAttackScanner,代码行数:26,代码来源:MethodUtils.java

示例12: invokeStaticMethod

import org.apache.commons.lang3.ClassUtils; //导入方法依赖的package包/类
/**
 * <p>Invokes a named {@code static} method whose parameter type matches the object type.</p>
 *
 * <p>This method delegates the method search to {@link #getMatchingAccessibleMethod(Class, String, Class[])}.</p>
 *
 * <p>This method supports calls to methods taking primitive parameters 
 * via passing in wrapping classes. So, for example, a {@code Boolean} class
 * would match a {@code boolean} primitive.</p>
 *
 * <p>This is a convenient wrapper for
 * {@link #invokeStaticMethod(Class, String, Object[], Class[])}.
 * </p>
 *
 * @param cls invoke static method on this class
 * @param methodName get method with this name
 * @param args use these arguments - treat {@code null} as empty array
 * @return The value returned by the invoked method
 *
 * @throws NoSuchMethodException if there is no such accessible method
 * @throws InvocationTargetException wraps an exception thrown by the
 *  method invoked
 * @throws IllegalAccessException if the requested method is not accessible
 *  via reflection
 */
public static Object invokeStaticMethod(final Class<?> cls, final String methodName,
        Object... args) throws NoSuchMethodException,
        IllegalAccessException, InvocationTargetException {
    args = ArrayUtils.nullToEmpty(args);
    final Class<?>[] parameterTypes = ClassUtils.toClass(args);
    return invokeStaticMethod(cls, methodName, args, parameterTypes);
}
 
开发者ID:Sukelluskello,项目名称:VectorAttackScanner,代码行数:32,代码来源:MethodUtils.java

示例13: invokeExactStaticMethod

import org.apache.commons.lang3.ClassUtils; //导入方法依赖的package包/类
/**
 * <p>Invokes a {@code static} method whose parameter types match exactly the object
 * types.</p>
 *
 * <p>This uses reflection to invoke the method obtained from a call to
 * {@link #getAccessibleMethod(Class, String, Class[])}.</p>
 *
 * @param cls invoke static method on this class
 * @param methodName get method with this name
 * @param args use these arguments - treat {@code null} as empty array
 * @return The value returned by the invoked method
 *
 * @throws NoSuchMethodException if there is no such accessible method
 * @throws InvocationTargetException wraps an exception thrown by the
 *  method invoked
 * @throws IllegalAccessException if the requested method is not accessible
 *  via reflection
 */
public static Object invokeExactStaticMethod(final Class<?> cls, final String methodName,
        Object... args) throws NoSuchMethodException,
        IllegalAccessException, InvocationTargetException {
    args = ArrayUtils.nullToEmpty(args);
    final Class<?>[] parameterTypes = ClassUtils.toClass(args);
    return invokeExactStaticMethod(cls, methodName, args, parameterTypes);
}
 
开发者ID:Sukelluskello,项目名称:VectorAttackScanner,代码行数:26,代码来源:MethodUtils.java


注:本文中的org.apache.commons.lang3.ClassUtils.toClass方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。