I want to use @OneOf
annotation from package io.dropwizard.validation;
Java usage:
@OneOf(value = {"m", "f"})
Kotlin usage: ???
I've tried this:
@OneOf(value = arrayOf("m", "f"))
and this:
@OneOf(value = ["m", "f"])
(EDIT: this example works since Kotlin 1.2, it supports array literal in annotation, thanks @BakaWaii)
All i get is :
Type inference failed. Expected type mismatch:
required: String
found:
Array<String>
Kotlin version: 1.1.2-2
We can use the library function arrayOf() to create an array by passing the values of the elements to the function. Since Array is a class in Kotlin, we can also use the Array constructor to create an array. The constructor takes two parameters: The size of the array, and.
annotation. Repeatable meta-annotation. This will make it repeatable both in Kotlin and Java. Java repeatable annotations are also supported from the Kotlin side.
Kotlin does not support inherited annotations.
Annotations are used to attach metadata to classes, interface, parameters, and so on at compile time. Annotation can be used by compiler which reflects at runtime. We can change the meaning of the data or program according to annotation values.
The value
parameter is automatically converted to a vararg parameter in Kotlin, as described in http://kotlinlang.org/docs/reference/annotations.html#java-annotations.
The correct syntax for this particular case is @OneOf("m", "f")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With