I am rewriting some of my java code int Kotlin and found a few deficiencies in annotation processing via kotlin.reflect
.
- Repeated annotations are not supported. The discussion on tracker points to the fact that repeated annotations are used rarely. But still they are used. Repeated annotations could be declared via array of annotations as I’ve pointed here. Still, reflections lack tools to work with repeated annotations. One could easily add those tools himself, but probably those tools should be in the library.
- Kotlin does not support inherited annotations. I understand that usage of annotations from superclass is quite rare, but it can happen (I myself use it a lot). I’ve opened a ticket in tracker for that: https://youtrack.jetbrains.com/issue/KT-22265.
And now something beyond java.
- In Java one can’t find if method overrides another method. So one can’t inherit annotations for methods. Kotlin currently also does not support it, but it could. It would be easy to do if reflections would provide
override
flag. The same goes for properties. - It seems that kotlin currently does not support providing class by String name, everyone uses Java calls for that. I think it should. It also could provide ways to find class members like properties and functions by name like
KProperty.forName('my.package.MyClass.myProperty')
.