AnnotationTarget.TYPE vs. AnnotationTarget.CLASS

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

@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:

annotation class TypeAnnotation

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

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

annotation class ClassAnnotation

class Foo
1 Like