Package io.github.toolfactory.narcissus
Class ReflectionCache
java.lang.Object
io.github.toolfactory.narcissus.ReflectionCache
ReflectionCache -- caches fields and methods of a class. Use this if you need to use reflection to access
multiple methods and/or fields, for speed.
-
Field Summary
FieldsModifier and TypeFieldDescription -
Constructor Summary
ConstructorsConstructorDescriptionReflectionCache
(Class<?> cls) Instantiate a new reflection cache for a class.ReflectionCache
(String className) Instantiate a new reflection cache for a named class. -
Method Summary
Modifier and TypeMethodDescriptionGet the field of the class that has a given field name.Get a method by name and parameter types.getMethods
(String methodName) Get all methods in the class for a given method name.
-
Field Details
-
methodNameToMethods
-
fieldNameToField
-
-
Constructor Details
-
ReflectionCache
Instantiate a new reflection cache for a class.- Parameters:
cls
- the class to instantiate.
-
ReflectionCache
Instantiate a new reflection cache for a named class.Finds the class by name (e.g.
"com.xyz.MyClass"
) using the current classloader or the system classloader. Finds array classes if the class name is of the form"com.xyz.MyClass[][]"
.- Parameters:
className
- the name of the class to instantiate.
-
-
Method Details
-
getField
Get the field of the class that has a given field name.- Parameters:
fieldName
- The name of the field.- Returns:
- The
Field
object for the requested field name, or null if no such field was found in the class.
-
getMethods
Get all methods in the class for a given method name. (There may be multiple methods with the same name but different parameter types).- Parameters:
methodName
- The name of the method.- Returns:
- A list of
Method
objects for methods of the requested method name, or null if no such method was found in the class.
-
getMethod
Get a method by name and parameter types.- Parameters:
methodName
- The name of the method.paramTypes
- The types of the parameters of the method. For primitive-typed parameters, use e.g. Integer.TYPE.- Returns:
- The
Method
object for the matching method, or null if no such method was found in the class.
-