hey!
I have an Interface MyInt and its implementation MyIntImp. I'm trying to define a custom annotation(\@MyAnnotation) which accepts one argument of type Class<MyInt>.
When I'm trying to use the annotation like this \@MyAnnotation(MyIntImp::class it gives me an error that it expects Class<MyInt> and not Class<MyIntImp>
what am i missing here?
j
Joffrey
02/17/2024, 11:30 PM
Class<T>
is invariant in its type parameter, so by default
Class<MyIntImp>
is not a subtype of
Class<MyInt>
even if
MyIntImp
is a subtype of
MyInt
.
You probably want
Class<out MyInt>
(with the
out
modifier) in your annotation declaration, not just