public final class ClassUtils extends Object
| 构造器和说明 |
|---|
ClassUtils() |
| 限定符和类型 | 方法和说明 |
|---|---|
static String |
getClassFilePath(Class<?> clazz)
获取类文件的路径(文件)
ClassUtils.getClassFilePath(ClassUtils.class) -> /Users/ponfee/scm/github/commons-core/target/classes/code/ponfee/commons/reflect/ClassUtils.class
ClassUtils.getClassFilePath(org.apache.commons.lang3.StringUtils.class) -> /Users/ponfee/.m2/repository/org/apache/commons/commons-lang3/3.12.0/commons-lang3-3.12.0.jar!
|
static String |
getClassName(Class<?> clazz)
获取类名称
ClassUtils.getClassName(ClassUtils.class) -> cn.ponfee.commons.reflect.ClassUtils
|
static String |
getClasspath()
获取当前的类路径(目录)
ClassUtils.getClasspath() -> /Users/ponfee/scm/github/commons-core/target/test-classes/
|
static String |
getClasspath(Class<?> clazz)
获取指定类的类路径(目录)
ClassUtils.getClasspath(ClassUtils.class) -> /Users/ponfee/scm/github/commons-core/target/classes/
ClassUtils.getClasspath(org.apache.commons.lang3.StringUtils.class) -> /Users/ponfee/.m2/repository/org/apache/commons/commons-lang3/3.12.0/
|
static <T> Constructor<T> |
getConstructor(Class<T> type,
Class<?>... parameterTypes) |
static Field |
getField(Class<?> clazz,
String fieldName)
Returns the member field(include super class)
|
static Method |
getMethod(Object caller,
String methodName,
Class<?>... parameterTypes) |
static String[] |
getMethodParamNames(Method method)
获取方法的参数名(编译未清除)
ClassUtils.getMethodParamNames(ClassUtils.class.getMethod("newInstance", Class.class, Class.class, Object.class)) -> [type, parameterType, arg]
|
static String |
getMethodSignature(Method method)
获取方法签名
ClassUtils.getMethodSignature(ClassUtils.class.getMethod("newInstance", Class.class, Class.class, Object.class)) -> public static java.lang.Object cn.ponfee.commons.reflect.ClassUtils.newInstance(java.lang.Class type, java.lang.Class parameterType, java.lang.Object arg)
|
static String |
getPackagePath(Class<?> clazz)
包名称转目录路径名
ClassUtils.getPackagePath(ClassUtils.class) -> code/ponfee/commons/reflect
|
static String |
getPackagePath(String packageName)
包名称转目录路径名
getPackagePath("cn.ponfee.commons.reflect") -> code/ponfee/commons/reflect
|
static Field |
getStaticField(Class<?> clazz,
String staticFieldName)
Returns the static field
|
static Tuple2<Class<?>,Field> |
getStaticFieldInClassChain(Class<?> clazz,
String staticFieldName)
Returns the static field, find in class pointer chain
|
static <T> T |
invoke(Object caller,
Method method) |
static <T> T |
invoke(Object caller,
Method method,
Object[] args) |
static <T> T |
invoke(Object caller,
String methodName) |
static <T> T |
invoke(Object caller,
String methodName,
Class<?>[] parameterTypes,
Object[] args) |
static <T> T |
invoke(Object caller,
String methodName,
Object[] args) |
static List<Field> |
listFields(Class<?> clazz)
Returns member field list include super class(exclude transient field)
|
static <T> T |
newInstance(Class<T> type) |
static <T> T |
newInstance(Class<T> type,
Class<?>[] parameterTypes,
Object[] args) |
static <T> T |
newInstance(Class<T> type,
Object[] args)
泛型参数的构造函数需要使用 {
newInstance(Class, Class[], Object[])}
ClassUtils.newInstance(Tuple3.class, new Object[]{1, 2, 3})
ClassUtils.newInstance(Tuple2.class, new Object[]{new String[]{"a", "b"}, new Integer[]{1, 2}}) |
static <T> T |
newInstance(Constructor<T> constructor) |
static <T> T |
newInstance(Constructor<T> constructor,
Object[] args) |
static Tuple2<Class<?>,Predicates> |
obtainClass(Object obj) |
public static String[] getMethodParamNames(Method method)
ClassUtils.getMethodParamNames(ClassUtils.class.getMethod("newInstance", Class.class, Class.class, Object.class)) -> [type, parameterType, arg]
method - the methodLocalVariableTableParameterNameDiscoverer.getParameterNames(Method)public static String getMethodSignature(Method method)
ClassUtils.getMethodSignature(ClassUtils.class.getMethod("newInstance", Class.class, Class.class, Object.class)) -> public static java.lang.Object cn.ponfee.commons.reflect.ClassUtils.newInstance(java.lang.Class type, java.lang.Class parameterType, java.lang.Object arg)
method - the methodMethod.toString(),
Method.toGenericString()public static Field getField(Class<?> clazz, String fieldName)
clazz - the typefieldName - the field namepublic static List<Field> listFields(Class<?> clazz)
clazz - the classpublic static Tuple2<Class<?>,Field> getStaticFieldInClassChain(Class<?> clazz, String staticFieldName)
clazz - the clazzstaticFieldName - the static field namepublic static Field getStaticField(Class<?> clazz, String staticFieldName)
clazz - the clazzstaticFieldName - the static field namepublic static String getClassName(Class<?> clazz)
ClassUtils.getClassName(ClassUtils.class) -> cn.ponfee.commons.reflect.ClassUtils
clazz - the classpublic static String getPackagePath(String packageName)
getPackagePath("cn.ponfee.commons.reflect") -> code/ponfee/commons/reflect
packageName - the package nameClassUtils.convertClassNameToResourcePath(java.lang.String)public static String getPackagePath(Class<?> clazz)
ClassUtils.getPackagePath(ClassUtils.class) -> code/ponfee/commons/reflect
clazz - the classpublic static String getClassFilePath(Class<?> clazz)
ClassUtils.getClassFilePath(ClassUtils.class) -> /Users/ponfee/scm/github/commons-core/target/classes/code/ponfee/commons/reflect/ClassUtils.class
ClassUtils.getClassFilePath(org.apache.commons.lang3.StringUtils.class) -> /Users/ponfee/.m2/repository/org/apache/commons/commons-lang3/3.12.0/commons-lang3-3.12.0.jar!/org/apache/commons/lang3/StringUtils.class
clazz - the classpublic static String getClasspath(Class<?> clazz)
ClassUtils.getClasspath(ClassUtils.class) -> /Users/ponfee/scm/github/commons-core/target/classes/
ClassUtils.getClasspath(org.apache.commons.lang3.StringUtils.class) -> /Users/ponfee/.m2/repository/org/apache/commons/commons-lang3/3.12.0/
clazz - the classpublic static String getClasspath()
ClassUtils.getClasspath() -> /Users/ponfee/scm/github/commons-core/target/test-classes/
public static <T> Constructor<T> getConstructor(Class<T> type, Class<?>... parameterTypes)
public static <T> T newInstance(Constructor<T> constructor)
public static <T> T newInstance(Constructor<T> constructor, Object[] args)
public static <T> T newInstance(Class<T> type, Class<?>[] parameterTypes, Object[] args)
public static <T> T newInstance(Class<T> type)
public static <T> T newInstance(Class<T> type, Object[] args)
newInstance(Class, Class[], Object[])} ClassUtils.newInstance(Tuple3.class, new Object[]{1, 2, 3})
ClassUtils.newInstance(Tuple2.class, new Object[]{new String[]{"a", "b"}, new Integer[]{1, 2}})
T - type - the typeargs - the argspublic static Method getMethod(Object caller, String methodName, Class<?>... parameterTypes)
public static <T> T invoke(Object caller, String methodName, Class<?>[] parameterTypes, Object[] args)
public static Tuple2<Class<?>,Predicates> obtainClass(Object obj)
Copyright © 2023. All rights reserved.