okaymak
03/19/2017, 8:24 PM@StringDef({ MyAnnotation.A, MyAnnotation.B, MyAnnotation.C})
@Retention(RetentionPolicy.SOURCE)
public @interface MyAnnotation {
String A = "A";
String B = "B";
String C = "C";
}
But in Kotlin you are forced to do it like this:
const val A = "A"
const val B = "B"
const val C = "C"
@StringDef(A, B, C)
@Retention(AnnotationRetention.SOURCE)
annotation class MyAnnotation
or either using an companion object
, but then a class is also required.
class MyKotlinAnnotation {
companion object {
const val A = "A"
const val B = "B"
const val C = "C"
}
}
@StringDef(MyKotlinAnnotation.Companion.A, MyKotlinAnnotation.Companion.B, MyKotlinAnnotation.Companion.C)
@Retention(AnnotationRetention.SOURCE)
annotation class MyAnnotation
Or is there another way doing this similar as in Java (by having the constants inside the annotation)?