Annotations 如何在注释Kotlin中使用类

Annotations 如何在注释Kotlin中使用类,annotations,kotlin,Annotations,Kotlin,我想创建一个接收类参数的注释,JAVA中的示例如下 @Retention(RUNTIME) public @interface CustomAnnotation { Class<Comparable<?>> comparator(); } @保留(运行时) public@interface自定义注释{ 类请参见以下语言参考: 如果需要将类指定为注释的参数,请使用Kotlin类(KClass) 因此,不要使用JavaClass,而是使用Kotlin等价物:KCl

我想创建一个接收类参数的注释,JAVA中的示例如下

@Retention(RUNTIME)
public @interface CustomAnnotation {

    Class<Comparable<?>> comparator();
}
@保留(运行时)
public@interface自定义注释{

类请参见以下语言参考:

如果需要将类指定为注释的参数,请使用Kotlin类(
KClass

因此,不要使用Java
Class
,而是使用Kotlin等价物:
KClass

@Retention(AnnotationRetention.RUNTIME)
注释类CustomAnnotation(
val比较器:KClass
)

可比性如何
?有关注释的文档说明了如何:
@Retention(AnnotationRetention.RUNTIME)
annotation class CustomAnnotation(

    val comparator: Class<Comparable<*>>
)
@Retention(AnnotationRetention.RUNTIME)
annotation class CustomAnnotation(
    val comparator: KClass<Comparable<*>>
)