當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。