AnnotationTarget.TYPE vs. AnnotationTarget.CLASS

I ran into an issue where a kotlin annotation was defined like this:

@Retention(AnnotationRetention.RUNTIME)
@ConfiguringAnnotation(RegisterKotlinMappersImpl::class)
@Target(AnnotationTarget.TYPE, AnnotationTarget.FUNCTION)
annotation class RegisterKotlinMappers(vararg val value: RegisterKotlinMapper)

and users complained that those could not be used on interfaces. The proposed solution is to change AnnotationTarget.TYPE to AnnotationTarget.CLASS. I would like to understand why this is the right fix.

what is the difference between the two annotation targets? I tried to find any documentation on the kotlin-lang web site and on stack overflow but so far I only found crickets.

We are using Kotlin 1.6.10, same problem exists on Kotlin 1.5.31. Target is Java 8 bytecode

Thank you for any pointers.

AnnotationTarget.CLASS is an annotation that can be applied to a class/interface declaration.
AnnotationTarget.TYPE is an annotation that can be applied to a type usage,
examples follow:

@Target(AnnotationTarget.TYPE)
annotation class TypeAnnotation

val l : List<@TypeAnnotation Int> = listOf()

fun foo(i: @TypeAnnotation Int) {}  // here note that "Int" is annotated, not i.

@Target(AnnotationTarget.CLASS)
annotation class ClassAnnotation

@ClassAnnotation
class Foo
1 Like