https://kotlinlang.org logo
#announcements
Title
# announcements
p

Paul Woitaschek

06/14/2017, 12:41 PM
I have about 20 annotations that need to be exactly like that but I want to avoid code duplication
😱 2
l

lovis

06/14/2017, 1:39 PM
paulwoitaschek: but… why? 😱
p

Paul Woitaschek

06/14/2017, 1:57 PM
Because code duplication is bad?
k

kirillrakhman

06/14/2017, 2:23 PM
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

lovis

06/15/2017, 7:35 AM
@Paul Woitaschek no, I meant why have 20 annotations
p

Paul Woitaschek

06/15/2017, 7:36 AM
I'm injecting perference classes of different types and I need qualifiers so my DI framework knows where each one has to go
l

lovis

06/15/2017, 7:40 AM
sounds like too much work to me 😉
p

Paul Woitaschek

06/15/2017, 7:44 AM
How would you inject the preferences with less work?
l

lovis

06/15/2017, 8:34 AM
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

marstran

06/15/2017, 8:34 AM
DI frameworks often support some kind of named or tagged bindings. Maybe that would work for you?
p

Paul Woitaschek

06/15/2017, 10:37 AM
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