alireza rahmaty :
I've created a custom annotation in java and I'm trying to use it in a Kotlin written class but in the compile time, I'm getting an error of
annotation parameter must be a compile-time constant
here is the code,
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.CLASS)
public @interface EdsFieldInfo {
int persianName();
String culomnName() default "";
int domainVals() default -1;
}
This is the place where I'm using the annotation
@EdsFieldInfo(persianName = R.string.customer_file_id, culomnName = "FileId")
@ColumnInfo(name = "FileId", typeAffinity = ColumnInfo.TEXT)
var fileId: String?,
and the error is shown here
persianName = R.string.customer_file_id
I try to find a solution for this but couldn't please help me to resolve this matter? Thank you.
shkschneider :
Since R
is compiled during compile-time, I would highly suspect you cannot use such R.string.customer_file_id
variable in an annotation. Maybe it gets evoluated before Android's builder actually builds R
.
So I'm afraid you should use a constant instead.