为什么禁止从类主构造函数自动生成Java可见的许多构造函数,默认params喜欢这个?
@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
此注释不适用于目标'
;
答案 0 :(得分:45)
这不是禁止的,您只是将@JvmOverloads
应用于错误的目标。注释主构造函数的正确方法是在constructor
之前明确指定@JvmOverloads
关键字:
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