You are currently viewing Altering annotation at runtime

Altering annotation at runtime

Method pMethod = Class.class.getDeclaredMethod(“annotationData”, null); pMethod.setAccessible(true);

Object annotationData = pMethod.invoke(Test.class);

Field annotationsXX = annotationData.getClass().getDeclaredField(“annotations”); annotationsXX.setAccessible(true);

Map<Class<? extends Annotation>, Annotation> map = (Map<Class<? extends Annotation>, Annotation>) annotationsXX.get(annotationData); map.put(Test.class,newAnnotation);

In Java, using reflection class annotation of a class can be set at runtime. Is there anyway to achieve the same thing in Kotlin?

submitted by /u/dipuu1990
[link] [comments]