public final class ClassUtils extends Object
| 限定符和类型 | 字段和说明 |
|---|---|
static Pattern |
QUALIFIED_CLASS_NAME_PATTERN |
| 构造器和说明 |
|---|
ClassUtils() |
| 限定符和类型 | 方法和说明 |
|---|---|
static Set<String> |
fieldDiff(Class<?> a,
Class<?> b) |
static <T> Class<T> |
getClass(String text)
Returns class object for text, can be class qualifier name or source code
|
static String |
getClassFilePath(Class<?> clazz)
获取类文件的路径(文件)
|
static String |
getClasspath()
获取当前的类路径(目录)
|
static String |
getClasspath(Class<?> clazz)
获取指定类的类路径(目录)
|
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 |
getObjectClassName(Object obj) |
static String |
getPackagePath(Class<?> clazz)
包名称转目录路径名
ClassUtils.getPackagePath(ClassUtils.class) -> code/ponfee/commons/reflect
|
static String |
getPackagePath(String packageName)
包名称转目录路径名
getPackagePath("cn.ponfee.commons.reflect") -> cn/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 final Pattern QUALIFIED_CLASS_NAME_PATTERN
public static <T> Class<T> getClass(String text)
text - the class qualifier name or source codepublic 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 getPackagePath(String packageName)
getPackagePath("cn.ponfee.commons.reflect") -> cn/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 <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 - class typetype - the classargs - 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)
public static String getClassFilePath(Class<?> clazz)
clazz - the classpublic static String getClasspath(Class<?> clazz)
clazz - the classpublic static String getClasspath()
Copyright © 2024. All rights reserved.