@ SuppressWarnings ( "unchecked" ) public static Object setAnnotationValue ( final Annotation annotation , final String key , final Object value ) throws NoSuchFieldException , SecurityException , IllegalArgumentException , IllegalAccessException { final Object invocationHandler = Proxy . getInvocationHandler ( annotation ) ; final Field field = invocationHandler . getClass ( ) . getDeclaredField ( "memberValues" ) ; field . setAccessible ( true ) ; final Map < String , Object > memberValues = ( Map < String , Object > ) field . get ( invocationHandler ) ; final Object oldValue = memberValues . get ( key ) ; if ( oldValue == null || oldValue . getClass ( ) != value . getClass ( ) ) { throw new IllegalArgumentException ( ) ; } memberValues . put ( key , value ) ; return oldValue ; }
Sets the annotation value for the given key of the given annotation to the given new value at runtime .