问题
As the title says I'm trying to modify a method's annotation String parameter at runtime in Java on Android. I've found an answer to another question asked some time ago which should solve the problem. However, it didn't on Android. In the linked answer there is the following code line
Object handler = Proxy.getInvocationHandler(annotation);
It assigns a libcore.reflect.AnnotationFactory Object to the handler variable. Three lines later in the code it is tried to get the class's field "memberValues", which is said to provide the annotation's member-value-pairs. It is realized using this line of code:
f = handler.getClass().getDeclaredField("memberValues");
However, Android's AnnotationFactory class does not have a field named "memberValues". That's why I get an exception telling me:
java.lang.NoSuchFieldException: No field memberValues in class Llibcore/reflect/AnnotationFactory; (declaration of 'libcore.reflect.AnnotationFactory' appears in /apex/com.android.art/javalib/core-libart.jar). Also, I cannot even access any declared fields of the class. I don't know why, but handler.getClass().getDeclaredFields()
is empty, although handler.getClass()
returns libcore.reflect.AnnotationFactory. I am trying to apply this runtime modification to the functionName value of a simple interface looking like this:
public interface LambdaFunctionInterface {
@LambdaFunction(functionName = "PLACEHOLDER")
Object lambdaFunction(Object request);
}
How can I realize it on Android? Where are the mentioned member-value-pairs of annotations stored on Android? Thanks a lot in advance!
来源:https://stackoverflow.com/questions/63429688/modify-a-method-definitions-annotation-string-parameter-at-runtime-on-android