How do i convert this java annotation to kotlin co...
# announcements
r
How do i convert this java annotation to kotlin code
@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
@Retention(RUNTIME)
@Documented
@Constraint(validatedBy = CustomerTypeSubSetValidator.class)
public @interface CustomerTypeSubset {
CustomerType[] anyOf();
String *message*() default "must be any of {anyOf}";
Class<?>[] groups() default {};
Class<? extends Payload>[] payload() default {};
}
m
Something like this?
Copy code
@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
@Retention(RUNTIME)
@Documented
@Constraint(validatedBy = CustomerTypeSubSetValidator.class)
annotation interface CustomerTypeSubset(
    val anyOf: Array<CustomerType>,
    val message: String = "must be any of {anyOf}",
    val groups: Array<Class<*>> = emptyArray(),
    val payload: Array<Class<out Payload>> = emptyArray())
https://kotlinlang.org/docs/annotations.html
Haven't tested it, because I don't know what CustomerTypeSubSetValidator, CustomerType and Payload is.
r
In java, anyOf, message, groups, payload seems method. How it can be property in kotlin?
t
we do something like
Copy code
@Constraint(validatedBy = [ValidPhoneNumberValidator::class])
@Target(AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.TYPE)
@Retention(AnnotationRetention.RUNTIME)
annotation class ValidPhoneNumber(
  val message: String = "must be a valid phone number",
  val groups: Array<KClass<*>> = [],
  val payload: Array<KClass<out Payload>> = [],
)
so I guess more or less as Marius wrote
but we wrote 100% kotlin, I don’t how this would look if used in Java