本文整理匯總了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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}