nayanjyoti
07/23/2017, 11:07 PMpublic class Person {
@CommandParameter("nm")
private String name;
@CommandParameter("ag")
private int age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
In java, I can get the annotation by simply field.getAnnotations()
I want to do the same thing, but I want this class to be a Kotlin data class.
I tried
data class Person( @CommandParameter("nm") val name: String,
@CommandParameter("ag") val age: Int)
But when I do field.getAnnotations(), i get an empty array.
I checked the java version of the kotlin code using the in build IDEA show decompiled java code, and I see that the fields indeed don’t have the annotations.
Can anyone suggest how to achieve the desired using kotlin?