Hello! Is it possible to create a typealias for an...
# announcements
p
Hello! Is it possible to create a typealias for an annotation? I want to do something like this (the code doesn't compile):
Copy code
import androidx.annotation.FloatRange

typealias ProgressFloatRange = FloatRange(from = 0.0, to = 1.0, fromInclusive = true, toInclusive = true)
t
1. I don't think what you're trying to do is possible 2. This is not how a typealias works. A typealias just creates a different name for the same thing, You could do
typealias MyAnnotation = FloatRange
, but you can't sorte an Annotation "instance" in a typealias (or anything else)
👆 1
m
Not with a typealias but I think you can create a new annotation that includes that annotation usage
Copy code
@FloatRange(from = 0.0, to = 1.0, fromInclusive = true, toInclusive = true)
annotation class ProgressFloatRange
the applicability depends on FloatRange retention and target, obviously
oh… now I see it’s something specific of Android SDK so no, I don’t think this can be done 😕
t
you see stuff like that quite often, esp. in things like Spring. But that's not a direct language feature. The code that analyzes the annotations has to be designed to look for meta annotations.
m
yeah I realized afterwards that you have no control over this, sorry