The problem with annotations in Kotlin
vitekkor opened this issue · 5 comments
Hi, @pholser ! I want to use your library in Kotlin, but I ran into some difficulties while writing the code, since all examples are only in java.
I wrote some code in java.
@Property
public void someTest(@Size(max=100) List<@InRange(minInt=0, maxInt=2) Integer> list) {
...
}
When trying to rewrite the same for Kotlin, the InRange annotation is not applied to the elements of my list. They are all generated in the range from Int.MIN_VALUE to Int.MAX_VALUE
@Property
fun someTest(@Size(max=100) list: List<@InRange(minInt=0, maxInt=2) Int>) {
...
}
Could you help me?
It’s a Kotlin problem. Kotlin just learned to emit Java Annotations for types. With a recent Kotlin version you can switch that feature on with a compiler argument:
-Xemit-jvm-type-annotations
@vitekkor -- thanks for sharing the info. I wonder if it would be worth noting this in junit-quickcheck's docs for future Kotlin users?
Noted. Closing ... thanks again!