Annotation typed array values

  

package java.lang.annotation;

@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.ANNOTATION_TYPE)
public @interface Target {
  ElementType value();
}


Documented
Retention(value = RetentionPolicy.RUNTIME)

// Error : Target(value = ElementType.FIELD, ElementType.CONSTRUCTOR)

// Error : Target(value = array(ElementType.FIELD, ElementType.CONSTRUCTOR))


// Error : Target(value = array<ElementType>(ElementType.FIELD, ElementType.CONSTRUCTOR))

// Error : Target(value = Array<ElementType>(ElementType.FIELD, ElementType.CONSTRUCTOR))
annotation class TestAnnotation(val a: String, val b: Int)

But, i don’t know write typed array ElementType[] value();

How to write typed array?

Kotlin sees array arguments of Java annotations as vararg automatically, try this:

Target(ElementType.FIELD, ElementType.CONSTRUCTOR)

Thank you Alexander!

I still think array() should work in annotation parameter. See https://youtrack.jetbrains.com/issue/KT-6641 for more discussion.