You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If java annotation value is array type, it will make getAnnotationsByType throw class cast issue, it seems that in java we can declare a single value for annotation value whose type is array, like this one
@Retention(CLASS)
public @interface JavaAnnotationWithList {
Class[] testList();
}
@JavaAnnotationWithList(testList = Main.class)
public class Main {
public static void main(String[] args) {
System.out.println("Hello world!");
}
}
If I use getAnnotationByType with Main class
val ksAnnotated = resolver.getSymbolsWithAnnotation(JavaAnnotationWithList::class.qualifiedName.toString())
ksAnnotated.forEach {
if (it is KSClassDeclaration) {
it.getAnnotationsByType(JavaAnnotationWithList::class).apply {
this.forEach { it.testList }
}
}
}
If java annotation value is array type, it will make getAnnotationsByType throw class cast issue, it seems that in java we can declare a single value for annotation value whose type is array, like this one
If I use getAnnotationByType with Main class
It will throw java.lang.ClassCastException
I have just made a simple reproduce for it: https://github.com/larryxiao625/KspGetJavaAnnotationTypeDemo, you can reproduce it with
./gradlew clean ksp-test:assemble -i
The text was updated successfully, but these errors were encountered: