Reputation: 26527
In Kotlin, I am trying to create an Annotation which can accept an array (vararg
) of other annotations.
I'm trying to do something like this:
annotation class MyAnnotation(
vararg val annotation: Annotation
)
The problem is it tells me Annotation
is not a valid parameter for annotation. If I try a specific annotation class, it works.
I'm trying to create an annotation which can take other annotations (for validations) and process them in order and do one unified effect.
Is there some special Kotlin syntax I can use to get it to let me provide an array of various annotation?
Upvotes: 3
Views: 1702
Reputation: 1089
I believe anything that is nullable (interfaces, Java types...) cannot be used as parameter to a Kotlin annotation. Maybe you could use
annotation class MyAnnotation(vararg val annotations: KClass<in Annotation>)
Upvotes: 1