Is there a way to call a method method in annotation
For example
@Annotation(param = Class.method();)
or is there anoter way?
It is possible by providing the name of the function into the annotation
Heres a class I wrote which contains the generic function 'callMethod()' which takes in a String and instance of a class and returns the result of calling that method.
public static <T> Object callMethod(String methodName, T classInstance) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
Method method = classInstance.getClass().getDeclaredMethod(methodName);
return method.invoke(classInstance);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.