ReflectUtils

Utility class to ease Reflection

Constructors

Link copied to clipboard
constructor()

Functions

Link copied to clipboard
open fun <T> allocateInstance(@NonNull clazz: Class<T>): T
Creates new class instance without using a constructor
Link copied to clipboard
open fun <T> getConstructorByArgs(@NonNull clazz: Class<T>, args: Array<Any>): Constructor<T>
Gets the constructor for class T matching the specified arguments
Link copied to clipboard
open fun getField(@NonNull instance: Any, @NonNull fieldName: String): Any
open fun getField(@NonNull clazz: Class<out Any>, @Nullable instance: Any, @NonNull fieldName: String): Any
Gets a field declared in the class.
Link copied to clipboard
open fun getMethodByArgs(@NonNull clazz: Class<out Any>, @NonNull methodName: String, args: Array<Any>): Method
Attempts to find and invoke the method matching the specified arguments Please note that this does not cache the lookup result, so if you need to call this many times you should do it manually and cache the Method to improve performance drastically
Link copied to clipboard
open fun <T> invokeConstructorWithArgs(@NonNull clazz: Class<T>, args: Array<Any>): T
Attempts to find and invoke the constructor of class T matching the specified arguments
Link copied to clipboard
open fun invokeMethod(@NonNull instance: Any, @NonNull methodName: String, args: Array<Any>): Any
open fun invokeMethod(@NonNull clazz: Class<out Any>, @Nullable instance: Any, @NonNull methodName: String, args: Array<Any>): Any
Attempts to find and invoke the method matching the specified arguments Please note that this does not cache the lookup result, so if you need to call this many times you should do it manually and cache the Method to improve performance drastically
Link copied to clipboard
open fun setField(@NonNull instance: Any, @NonNull fieldName: String, @Nullable v: Any)
open fun setField(@NonNull clazz: Class<out Any>, @Nullable instance: Any, @NonNull fieldName: String, @Nullable v: Any)
Override a field of a class.
Link copied to clipboard
open fun setFinalField(@Nullable instance: Any, @NonNull fieldName: String, @Nullable v: Any)
open fun setFinalField(@NonNull clazz: Class<out Any>, @Nullable instance: Any, @NonNull fieldName: String, @Nullable v: Any)
Override a final field of a class.