Annotation alias

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"
7 Likes

Oh yes please!

I have soooo many of these:

@JsonDeserialize(using = MyFiniteAbsDoubleDeserializer::class) val value: Double

in data classes for @PostMapping controllers (which is a simple but handy deserializer that checks for double values to be finite [no NaN or Infinity] and always makes them positive)

and it would be so much nicer to just say @FiniteAbsDouble as an annotationalias

1 Like

So, basically we want to replicate what Spring offers, but on a language level: https://www.baeldung.com/spring-aliasfor-annotation

1 Like

This would be useful also to use an alias for multiple annotations