Annotation typed array values


package java.lang.annotation;

public @interface Target {
  ElementType value();

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 for more discussion.