Kotlin annotations can only use the following as construction parameters:
- Types that correspond to Java primitive types (Int, Long etc.)
- Strings
- Classes (
Foo::class
)
- Enums
- Other annotations
- Arrays of the types listed above
Generic types are not allowed.
In your situation you'll either have to make two constructors, one for each type:
annotation class BotCommandScopeChatIntId(
val type: String = "chat",
val chatId: Int,
)
annotation class BotCommandScopeChatStringId(
val type: String = "chat",
val chatId: String,
)
Or have two constructor parameters, one for each type:
annotation class BotCommandScopeChat(
val type: String = "chat",
val chatIdString: String? = null,
val chatId: Int? = null,
)
These will have to have default parameters, else users will always have to provide one, even if they don't need to.
Or (and this would be my preference), just use a String, and convert it to an Int if necessary.
annotation class BotCommandScopeChat(
val type: String = "chat",
val chatId: String,
)