Kotlin的Java注释实现

Kotlin的Java注释实现,kotlin,Kotlin,我试图将@Age constraint(在线找到)的实现从Java复制到Kotlin,我复制了Java代码库,并使用IDE将其转换为Kotlin代码 Java代码 @Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE }) @Retention(RUNTIME) @Repeatable(Age.List.class) @Documented @Constraint(validatedBy = { })

我试图将@Age constraint(在线找到)的实现从Java复制到Kotlin,我复制了Java代码库,并使用IDE将其转换为Kotlin代码

Java代码

@Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE })
@Retention(RUNTIME)
@Repeatable(Age.List.class)
@Documented
@Constraint(validatedBy = { })
public @interface Age {
    String message() default "Must be greater than {value}";
    Class<?>[] groups() default { };
    Class<? extends Payload>[] payload() default { };
    long value();
    @Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE })
    @Retention(RUNTIME)
    @Documented
    @interface List {
        Age[] value();
    }
}
@Target({方法、字段、注释\类型、构造函数、参数、类型\使用})
@保留(运行时)
@可重复(年龄.列表.类别)
@记录
@约束(validatedBy={})
公共@接口时代{
字符串消息()默认值“必须大于{value}”;
类[]组()默认值{};

类是的,您需要将
列表
时代
中移出。在Kotlin的未来版本中,很可能会取消对在注释中嵌套类的限制;这与其说是一个基本问题,不如说是一个设计疏忽

@Target(AnnotationTarget.*)  
@Retention(RUNTIME)  
@Repeatable(Age.List::class)  
@Documented  
@Constraint(validatedBy = arrayOf())  
annotation class Age(  
  val value: Long,  
  val message: String = "Must be greater than {value}",  
  val groups: Array<KClass<*>> = arrayOf(),  
  val payload: Array<KClass<out Payload>> = arrayOf()) { 

  @Target(AnnotationTarget.FUNCTION,  
    AnnotationTarget.PROPERTY_GETTER,  
    AnnotationTarget.PROPERTY_SETTER,  
    AnnotationTarget.FIELD,  
    AnnotationTarget.ANNOTATION_CLASS,  
    AnnotationTarget.CONSTRUCTOR,  
    AnnotationTarget.VALUE_PARAMETER,  
    AnnotationTarget.TYPE)  
  @Retention(RUNTIME)  
  @Documented  
  annotation class List(vararg val value: Age)  
}