Why is it prohibited to autogenerate many constructors visible to Java from class primary constructor with default params likes this?
@JvmOverloads class Video(private val id: Long, val ownerId: Long, var title: String? = null, var imgLink: String? = null, var videoLink: String? = null, var description: String? = null, var created: Date? = null, var accessKey: String? = null, var duration: Long? = null, var views: Long? = null, var comments: Long? = null) : Entity
This annotation is not applicable to target 'class'
The @JvmOverloads annotation is a convenience feature in Kotlin for interoperating with Java code, but there is one specific use case on Android where it shouldn't be used carelessly. Let's first look at what this annotation does, and then get to the specific issue.
@JvmField indicates weather the kotlin compiler should generate getters/setters for this property or not. If its set then it will not generate getters/setters for this property . You can omit it in this case .
Put simply, this annotation tells the Kotlin compiler to generate one additional static method for the annotated function under the hood. Moreover, the most important use case for this annotation is, of course, better Java interoperability.
It's not prohibited, you are just applying @JvmOverloads
to the wrong target. The proper way to annotate primary constructor is to explicitly specify constructor
keyword with @JvmOverloads
before:
class Video @JvmOverloads constructor( private val id: Long, val ownerId: Long, var title: String? = null, var imgLink: String? = null, var videoLink: String? = null, var description: String? = null, var created: Date? = null, var accessKey: String? = null, var duration: Long? = null, var views: Long? = null, var comments: Long? = null ) : Entity
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