Kotlin annotation alias
Asked Answered
C

0

6

Is it somehow possible to have "annotation aliases" in Kotlin?

What I want to achieve is to transform this

@Colour("red")
fun method() = "something"

into something like this

annotationalias Red = Colour("red")

@Red
fun method() = "something"
Chandrachandragupta answered 9/6, 2022 at 10:16 Comment(3)
That would be a cool feature, but it is currently not in Kotlin. You need to write your own annotation called Red, and write your own annotation processor that translates it into Colour("red").Absquatulate
If you have control over the processor that's reading the annotations, you can change it to search for aliases manually. Some libraries already include this, like Spring Boot's meta-annotations and composed annotations.Minify
See also https://mcmap.net/q/1918721/-how-to-combine-several-annotation-into-one-in-kotlin/4161471Minify

© 2022 - 2024 — McMap. All rights reserved.