Reputation: 12932
I am learning Kotlin.
I developed one library in Java based on annotation processing. This library works perfectly on Java. My library contains annotations which the user can put on class fields. But that field should not be private
or static
in order to process that field.
@MyAnnotation
private String userName;
This will throw a compile-time error suggesting the user to remove the private
modifier to be processed by my library's annotation processor.
Once user removes private
it's working.
Now in case of Kotlin
@MyAnnotation
var spUserName : String? = null
This is generating the private field like below.
...
private java.lang.String spUserName;
...
So my annotation processor is throwing a compile-time error.
After searching the web, adding @JvmField
on that field is working perfectly like below.
@JvmField
@MyAnnotation
var spUserName : String? = null
But I don't want my users to add one more annotation above my annotation. It increasing the code if there are so many fields.
Please suggest any other alternative to avoid @JvmField
.
So my question is: how can I make my field non-private in Kotlin without using @JvmField
?
Upvotes: 2
Views: 1066