简体   繁体   中英

An annotation argument must be a compile-time constant when trying to convert java enum

I tried to convert a java file to kotlin file but i'm getting this error: An annotation argument must be a compile-time constant

@StringDef(
    BillingEnum.ALL,
    BillingEnum.PAID,
    BillingEnum.PENDING,
    BillingEnum.OVERDUE,
    BillingEnum.OPEN,
    BillingEnum.DELETED
)
annotation class BillingEnum {
    companion object {
        var ALL = ""
        var PAID = "paid"
        var PENDING = "pending"
        var OVERDUE = "overdue"
        var OPEN = "open"
        var DELETED = "deleted"
    }
}

Before it looked like this:

@StringDef({
        BillingEnum.ALL,
        BillingEnum.PAID,
        BillingEnum.PENDING,
        BillingEnum.OVERDUE,
        BillingEnum.OPEN,
        BillingEnum.DELETED
})
public @interface BillingEnum {
    String ALL = "";
    String PAID = "paid";
    String PENDING = "pending";
    String OVERDUE = "overdue";
    String OPEN = "open";
    String DELETED = "deleted";
}

You must write

annotation class BillingEnum {
    companion object {
        const val ALL = ""
        const val PAID = "paid"
        const val PENDING = "pending"
        const val OVERDUE = "overdue"
        const val OPEN = "open"
        const val DELETED = "deleted"
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM