Referring to https://developer.android.com/reference/android/support/annotation/StringDef https://developer.android.com/reference/android/support/annotation/IntDef
I could easily create my compile validation which limits my String parameter to specific type of String (in Java)
e.g.
import android.support.annotation.StringDef;
import java.lang.annotation.Retention;
import static java.lang.annotation.RetentionPolicy.SOURCE;
@Retention(SOURCE)
@StringDef({
"allow_one",
"okay_two"
})
public @interface AllowedString { }
So if I have
class TestAnnotation(@AllowedString private val name: String) {
fun printName(@AllowedString name: String) {}
}
And when I code
val testAnnotation = TestAnnotation("not_allowed")
Android Studio will flag error on the not_allowed
as it is not in the list.
If I convert to Kotlin the AllowedString
annotation interface as below, it doesn't works anymore. Why?
import android.support.annotation.StringDef
import java.lang.annotation.Retention
import java.lang.annotation.RetentionPolicy.SOURCE
@Retention(SOURCE)
@StringDef("allow_one", "okay_two")
annotation class AllowedString
Why?