I have about 20 annotations that need to be exactl...
# announcements
p
I have about 20 annotations that need to be exactly like that but I want to avoid code duplication
😱 2
l
paulwoitaschek: but… why? 😱
p
Because code duplication is bad?
k
some frameworks support meta annotations, i.e. you write
Copy code
@Qualifier
@Target(AnnotationTarget.PROPERTY, AnnotationTarget.FUNCTION)
@Retention(AnnotationRetention.RUNTIME)
annotation class MetaAnn

@MetaAnn
annotation class Something
l
@Paul Woitaschek no, I meant why have 20 annotations
p
I'm injecting perference classes of different types and I need qualifiers so my DI framework knows where each one has to go
l
sounds like too much work to me 😉
p
How would you inject the preferences with less work?
l
I probably wouldn’t inject them at all, but I don’t know your use case or your app, so I’m sure that it’s the best solution in your case.
m
DI frameworks often support some kind of named or tagged bindings. Maybe that would work for you?
p
I like it that way. I want to inject them for testing, that's easier. And once I set up these qualifiers, it's real clear code