本文整理汇总了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);
}