Package com.xxl.tool.core
Class ReflectionTool
java.lang.Object
com.xxl.tool.core.ReflectionTool
Reflection Tool
- Author:
- xuxueli 2024-01-21 05:03:10
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceCallback interface invoked on each field in the hierarchy. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voiddoWithFields(Class<?> clazz, ReflectionTool.FieldCallback fc) iterate processing fieldsstatic Fieldfind field of class by field namestatic Fieldfind field of class by field name and field typestatic MethodfindMethod(Class<?> clazz, String name, Class<?>... paramTypes) find method of class by method method name and paramsstatic Objectget field valuestatic StringgetPackageName(Class<?> clazz) Returns the package name ofclazzstatic StringgetPackageName(String classFullName) Returns the package name ofclassFullNamestatic ObjectinvokeMethod(Method method, Object target, Object... args) invoke methodstatic booleanisPublicStaticFinal(Field field) check field is public static finalstatic voidmakeAccessible(Field field) make field accessiblestatic voidmakeAccessible(Method method) make method accessiblestatic <T> TnewProxy(Class<T> interfaceType, InvocationHandler handler) return a proxy instance that implements the specified interfaceTypestatic voidset field value
-
Constructor Details
-
ReflectionTool
public ReflectionTool()
-
-
Method Details
-
getPackageName
Returns the package name ofclazz- Parameters:
clazz- the class to introspect- Returns:
- package name of
clazz
-
getPackageName
Returns the package name ofclassFullName- Parameters:
classFullName- the class to introspect- Returns:
- package name of
classFullName
-
findMethod
find method of class by method method name and params- Parameters:
clazz- the class to introspectname- the name of the methodparamTypes- the parameter types of the method- Returns:
- the Method object, or
nullif none found
-
makeAccessible
make method accessible- Parameters:
method- the method to make accessible
-
invokeMethod
invoke method- Parameters:
method- method to invoketarget- target object to invokeargs- arguments to pass into method- Returns:
- method invoke result
-
findField
find field of class by field name- Parameters:
clazz- class to introspectname- name of the field- Returns:
- field object, or
nullif none found
-
findField
find field of class by field name and field type- Parameters:
clazz- class to introspectname- name of the fieldtype- type of the field- Returns:
- field object, or
nullif none found
-
makeAccessible
make field accessible- Parameters:
field- field to make accessible
-
setField
set field value- Parameters:
field- field to settarget- target object to setvalue- value to set
-
getField
get field value- Parameters:
field- field to gettarget- target object to get- Returns:
- field value
-
isPublicStaticFinal
check field is public static final- Parameters:
field- field to check- Returns:
- true if field is public static final
-
doWithFields
iterate processing fields- Parameters:
clazz- class to introspectfc- callback to invoke for each field
-
newProxy
return a proxy instance that implements the specified interfaceType- Type Parameters:
T- the type of the proxy- Parameters:
interfaceType- interfaceType to implementhandler- handler to handle method invocation- Returns:
- a proxy instance
-