Class ReflectionCache

java.lang.Object
io.github.toolfactory.narcissus.ReflectionCache

public class ReflectionCache extends Object
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 Details

  • Constructor Details

    • ReflectionCache

      public ReflectionCache(Class<?> cls)
      Instantiate a new reflection cache for a class.
      Parameters:
      cls - the class to instantiate.
    • ReflectionCache

      public ReflectionCache(String className)
      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

      public Field getField(String fieldName)
      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

      public List<Method> getMethods(String methodName)
      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

      public Method getMethod(String methodName, Class<?>... paramTypes)
      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.